Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!usc!apple!olivea!tymix!cirrusl!ss131!dhesi From: dhesi%cirrusl@oliveb.ATC.olivetti.com (Rahul Dhesi) Newsgroups: comp.lang.c Subject: Re: EXE file size, C vs. Pascal Keywords: C, Pascal, MsDos Message-ID: <2697@cirrusl.UUCP> Date: 14 Nov 90 03:12:17 GMT References: <16398@mentor.cc.purdue.edu> <4302@sactoh0.SAC.CA.US> Sender: news@cirrusl.UUCP Organization: Cirrus Logic Inc. Lines: 44 (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 UUCP: oliveb!cirrusl!dhesi