DeSmet C - making smaller .EXE files

dgary at ecsvax.UUCP dgary at ecsvax.UUCP
Fri Jul 6 02:18:49 AEST 1984


title: DeSmet C internals - interesting discoveries
newsgroups: micro.ibmpc, net.micro.pc, net.lang.c

The following summarizes my most important discoveries about Mark DeSmet
C's I/O routines:

1) exit(), putchar(), getchar(), puts(), ci(), co(), and csts() are
permanent parts of the startup code and you will save no space by writing
your own.  The startup code also contains some of the memory management
stuff.

2) bind includes all .o files listed on the command line in the output
.exe file, even those containing no routines needed by the main program.

3) When .o files are combined into a library (.s) file, each of the
original .o files is treated as an indivisible unit.  If (and only if)
bind needs a routine from a library, it brings in the whole unit.  Moral
is to keep your .o files small and collect them into libraries.

4) The CREAT2.C file on the "Hacker" disk ($25 from CWare, reviewed in a
separate posting) contains DOS 2.x routines.  Compiling CREAT2.C and using

  bind foo.o ... creat2.o

will produce an .exe file that will only work under DOS 2.x.  It may or
may not be smaller than one linked without creat2, depending upon whether
you use printf().  Anything that uses printf(), scanf(), or even
sprintf() or sscanf() seems to drag in the whole DeSmet i/o library
(including the bisexual DOS 1&2 routines and probably his memoirs) and
will be a minimum 6K.  A program to print "Hello" will be 1.5K using
puts(), 6K with printf()!  Programs doing file I/O that use CREAT2 and
avoid printf() can save as much as 3.5K.

5) The documentation is right: getchar() can't handle redirected input
very well.  (This is because DeSmet uses the "old" DOS calls for
getchar().  The ISETUP.A file on "Hacker" shows a conditional DOS 2.0
call, but it is commented out with no indication why.)  You can get
working redirection by using the macro "#define getchar() getc(stdin)".
For several reasons, including space, I'd suggest going to this only when
I/O redirection is actually anticipated.  Try it.

6) Like a lot of very fine programmers, DeSmet would not last 4 seconds
in a spelling bee against a parakeet.

The publisher is CWare, PO Box 710097, San Jose, CA 95171-0097;
phone (408) 736-6905 9am-1pm Pacific time for orders or technical
questions.  As usual, I have no connection with this firm except
as a customer.



More information about the Comp.lang.c mailing list