EXE file size, C vs. Pascal

Rahul Dhesi dhesi%cirrusl at oliveb.ATC.olivetti.com
Wed Nov 14 14:12:17 AEST 1990


(MS-DOS specific stuff follows.)

I found that executables resulting from Turbo C 1.0 compilations could
be made much smaller if I wrote my own customized C run-time
initilization code.  The standard run-time stuff under MS-DOS does zero
or more of the following things:

- Put some standard things in global variables.  E.g.
  MS-DOS version  and address of PSP (program segment prefix).

- Allocate BSS space (if not already done during loading).
  Initialize BSS data to zeroes.

- Allocate space for a stack, exit with error if insufficient
  space available.

- If the program uses near data, make the environment variables
  available in near memory by allocating memory and making a local copy
  of the environment.

- Initialize a block of memory at address 0 (or offset 0), for
  later checking of NULL pointer dereferencing.  (There may be no
  actual run-time initialization, but the memory is still allocated,
  and may take up space in the executable.)

- Collect arguments from the command line.  Test for MS-DOS
  version;  if 3.0 or greater, initilize argv[0] from the pathname
  following the environment data, else initilize argv[0] to point to a
  null character.  Allocate memory for argv[1] onwards.  Parse command
  line, interpreting blank, tab, double quotes, and backslash-
  quoted-double-quote intelligently.  Split command line into tokens,
  allocate memory, and initialize argv[1] onwards.

- Call main() with parameters.  Wait for return.  Upon return,
  check memory at address 0 for possible NULL pointer dereference
  and possibly print an error message.

- If stdio was linked in, call a routine to close all files.

- Exit back to MS-DOS, supplying the exit system call with the return
  code received from main().
--
Rahul Dhesi <dhesi%cirrusl at oliveb.ATC.olivetti.com>
UUCP:  oliveb!cirrusl!dhesi



More information about the Comp.lang.c mailing list