Path: utzoo!utgpu!water!watmath!clyde!burl!codas!mtune!whuts!homxb!houdi!marty1 From: marty1@houdi.UUCP (M.BRILLIANT) Newsgroups: comp.lang.c Subject: Re: exit(main(argc,argv,env)); Message-ID: <1451@houdi.UUCP> Date: 17 Dec 87 18:00:10 GMT References: <10875@brl-adm.ARPA> Organization: AT&T Bell Laboratories, Holmdel Lines: 26 > > I was looking through the file crt0.c in the GNU emacs source code and > found the command > > 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 ? > > ADLER1@BRANDEIS.BITNET Yeah, I second the question. What this does is execute main(...) and then give exit() the number that main returns. So main(...) must have in it some statements of the form return(3); or return(status); so that exit() will get a useful number. But the same effect would be achieved if main() had statements of the form exit(3); or exit(status);. The key question is where the exit(main(..)) was found. Since main() is the first function called, no statement is needed to invoke main(). Put it another way, since main() is invoked anyway, any statement that calls main() must call it recursively. Why would anybody do that? M. B. Brilliant Marty AT&T-BL HO 3D-520 (201)-949-1858 Holmdel, NJ 07733 ihnp4!houdi!marty1