www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - Eliminate duplicated strings ...

↑ ↓ ← mx0 seznam.cz writes:
Is any option of dmc to eliminate duplicated strings in the final executables
while linking? (like e.g. in msvc); and possibly storing string constants (like
__FILE__) in read only memory - I didn't found anything, even with -o+space the
strings are still duplicated in the executable ... normally it is not problem,
except .exe size, but when I build 16-bit DOS exes and use __FILE__ in debugging
macros, I often reach the DOS data seg size limit :-/
Jul 24 2005
↑ ↓ "Walter" <newshound digitalmars.com> writes:
<mx0 seznam.cz> wrote in message news:dbvn4v$2576$1 digitaldaemon.com...
 Is any option of dmc to eliminate duplicated strings in the final

 while linking? (like e.g. in msvc); and possibly storing string constants

 __FILE__) in read only memory - I didn't found anything, even

 strings are still duplicated in the executable ... normally it is not

 except .exe size, but when I build 16-bit DOS exes and use __FILE__ in

 macros, I often reach the DOS data seg size limit :-/

Here's an old technique I used for developing DOS programs because of that problem. -------------------------------- static char __file__[] = __FILE__; #undef assert #define assert(e) ((e) || (local_assert(__LINE__), 0)) void my_assert ( char * , int ); static void local_assert(int line) { my_assert(__file__,line); } ------------------------------------------ which cuts down a lot on the size of the code generated by assert().
Jul 24 2005
↑ ↓ mx0 seznam.cz writes:
In article <dc0hsp$1ho$1 digitaldaemon.com>, Walter says...
Here's an old technique I used for developing DOS programs because of that
problem.

--------------------------------
static char __file__[] = __FILE__;

#undef assert
#define assert(e) ((e) || (local_assert(__LINE__), 0))

void my_assert ( char * , int );

static void local_assert(int line)
{
    my_assert(__file__,line);
}
------------------------------------------

which cuts down a lot on the size of the code generated by assert().

Ok, I know this technique, I only asked if I have some options to do it more natively (and furthermore, this technique, AFAIK, won't work in headers, e.g. inside class templates, 'cause I think I cannot use "static char __file__[] = __FILE__;" in header file included to more cpps). That means, there is no such stuff in dmc, em I right? (I know, rely on this functionality is not the best approach, while the C/C++ compiler is not liable to do such optimization, but it were very handy especially for 16-bit DOS programs). Never mind, I will try to do thinks I need smarter way :). But anyway, thanks for reply.
Jul 25 2005
↑ ↓ → "Walter" <newshound digitalmars.com> writes:
<mx0 seznam.cz> wrote in message news:dc24oa$19ak$1 digitaldaemon.com...
 Ok, I know this technique, I only asked if I have some options to do it

 natively (and furthermore, this technique, AFAIK, won't work in headers,

 inside class templates, 'cause I think I cannot use "static char

 __FILE__;" in header file included to more cpps). That means, there is no

 stuff in dmc, em I right? (I know, rely on this functionality is not the

 approach, while the C/C++ compiler is not liable to do such optimization,

 were very handy especially for 16-bit DOS programs). Never mind, I will

 do thinks I need smarter way :). But anyway, thanks for reply.

I know you can't get it all into a .h file, but here's what I do: static char __file__[] = __FILE__; #include "tassert.h" It's just two lines that are boilerplate cut & paste per source file. It is especially handy for DOS programs, because not only does it share the __FILE__ string, the local assert function will always be a 'near' function (saving bytes) and each assert only generates the __LINE__ (the __file__ is supplied by the near function), saving even more bytes.
Jul 30 2005