Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-ncis!helios.ee.lbl.gov!pasteur!ames!husc6!bloom-beacon!adam.pika.mit.edu!scs From: scs@adam.pika.mit.edu (Steve Summit) Newsgroups: comp.lang.c Subject: Re: main() and exit() (was: Strange lint mumblings) Summary: how to keep executables small Message-ID: <8634@bloom-beacon.MIT.EDU> Date: 6 Jan 89 05:26:54 GMT References: <416@marob.MASA.COM> <11467@dartvax.Dartmouth.EDU> <179@amsdsg.UUCP> <599@micropen> <1700@valhalla.ee.rochester.edu> <282@twwells.uucp> <7082@batcomputer.tn.cornell.edu> <9253@smoke.BRL.MIL> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: scs@adam.pika.mit.edu (Steve Summit) Lines: 45 In article <7082@batcomputer.tn.cornell.edu> braner@tcgould.tn.cornell.edu (Moshe Braner) writes: >On systems I have worked on, calling exit() links in most of the >STDIO library modules, resulting in an executable program that is >much bigger than it needs to be... In article <9253@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >This didn't happen on UNIX systems before "ranlib" invaded, because >the C library provided two modules containing the same entry point, >one linked in when any part of STDIO was linked and the other module >otherwise. I frequently use another technique to keep executables small, which requires neither manipulation of library ordering nor atexit/onexit, and works fine in the presence of ranlib. To solve the _cleanup problem, I'd write exit as: int (*_cleanupptr)() = NULL; exit(status) int status; { if(_cleanupptr != NULL) (*_cleanupptr)(); _exit(status); } and then put extern int (*_cleanupptr)(); extern int _cleanup(); ... _cleanupptr = _cleanup; in fopen and/or _flsbuf. _cleanup is therefore not one of exit's undefined externals, and won't get pulled in unless stdio is actually used. I'm not sure if I saw this technique somewhere or if I invented it. If the latter, remember, you saw it here first! :-) Steve Summit scs@adam.pika.mit.edu