Path: utzoo!utgpu!water!watmath!clyde!rutgers!sri-spam!ames!hao!oddjob!gargoyle!ihnp4!homxb!houxa!jph From: jph@houxa.UUCP (J.HARKINS) Newsgroups: comp.lang.c Subject: Re: exit(main(argc,argv,env)); Message-ID: <1885@houxa.UUCP> Date: 18 Dec 87 19:56:10 GMT References: <10875@brl-adm.ARPA> <1253@homxb.UUCP> Organization: AT&T Bell Laboratories, Holmdel Lines: 25 In article <10875@brl-adm.ARPA>, ADLER1%BRANDEIS.BITNET@CUNYVM.CUNY.EDU writes: > > exit(main(argc,argv,env)); > > which I find puzzling. I thought that one was supposed to give exit a > number for an argument. What does the above command do and why would > anyone want to do it that way ? As the other posters have noted, main() returns an int which is what exit() needs. However, doing this also ensures that exit() will be called, even if it is never explicitely called from main(). exit() may flush buffers, close files, and perform other chores required for nice, systematic completion of a C program. How many times have you seen buffered output not get printed because a program died between the output statement and the physical flushing of its output buffer? The exit(main()) ensures that things like this should not happen. ------- Disclaimer: I hereby disclaim all my debts. ------ Jack Harkins @ AT&T Bell Labs Princeton Information (201) 949-3618 (201) 356-7573 ihnp4!houxa!jph