Path: utzoo!utgpu!water!watmath!clyde!rutgers!ames!fxgrp!ljz From: ljz@fxgrp.UUCP (Lloyd Zusman, Master Byte Software) Newsgroups: comp.lang.c Subject: Re: exit(main(argc,argv,env)); Message-ID: <184@fxgrp.UUCP> Date: 19 Dec 87 01:07:32 GMT References: <10875@brl-adm.ARPA> <176@fxgrp.UUCP> <1286@laidbak.UUCP> Reply-To: fxgrp!ljz@ames.arpa (Lloyd Zusman, Master Byte Software) Followup-To: <1286@laidbak.UUCP> daveb@laidbak.UUCP (Dave Burton) Organization: FX Development Group, Inc., Mountain View, CA Lines: 40 In article <1286@laidbak.UUCP> daveb@laidbak.UUCP (Dave Burton) writes: >In article <176@fxgrp.UUCP> fxgrp!ljz@ames.arpa (Lloyd Zusman, Master Byte Software) writes: >>In article <10875@brl-adm.ARPA> ADLER1%BRANDEIS.BITNET@CUNYVM.CUNY.EDU writes: > ... >At least in the UNIX environment, exit() is a function that flushes all >buffers (and closes all file descriptors?), as well as handling functions >registered via onexit(), finally calling _exit(), a system call that >never returns. > >Using return instead of exit() bypasses this cleanup operation. In the GNU version of crt0.o, this is obviously not the case due to the exit(main(argc, argv, envp)); statement in the GNU crt0.c file. In this case, using the return statement to leave main() will indeed cause all the cleanup functions to take place because this results in an immediate exit() call from the crt0 module [ i.e., *not* an _exit() call ]. I have been told here that our SunOS version 3.4 system works the same way as the GNU crt0 module is written, and hence at least on our unix, return(N) and exit(N) will be the same if issued from main() [ assuming, of course that my source of information about SunOS is correct ]. But upon reflection, I have to agree that it is better to always use an exit() statement in main() instead of relying on return [ or even worse, using neither return nor exit(), as is often done ]. If even one C compiler doesn't use exit() with main() the way it is done in the GNU crt0 module, then you have unpredictable results if exit() is left out of main(). So, to be safe, always leave main() via exit(). ------------------------------------------------------------------------- Lloyd Zusman Master Byte Software Los Gatos, California Internet: fxgrp!ljz@ames.arpa "We take things well in hand." UUCP: ...!ames!fxgrp!ljz