Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!mtune!westmark!dave From: dave@westmark.UUCP (Dave Levenson) Newsgroups: comp.lang.c Subject: Re: exit(main(argc,argv,env)); Message-ID: <314@westmark.UUCP> Date: 19 Dec 87 00:19:12 GMT References: <10875@brl-adm.ARPA> <1451@houdi.UUCP> Organization: Westmark, Inc., Warren, NJ, USA Lines: 32 In article <1451@houdi.UUCP>, marty1@houdi.UUCP (M.BRILLIANT) writes: > > > > I was looking through the file crt0.c in the GNU emacs source code and > > found the command > > > > exit(main(argc,argv,env)); > > ... > 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? Why call main() ? Well, you, yourself, said that main is the first function _called_. This implies that someone calls main. The code that actually receives control from the operating system is a runtime initialization function called crt0. It establishes the runtime stack, the local copy of the environment, and the arguments, and then calls main(). In other words, main() is not the first function to be called, it is the first user-written function to be called. It is called by crt0, which is not application-specific, and generally supplied by the compiler-writer. Main may call exit() explicitly, or it may return to its caller. In the latter case, its caller calls exit, apparently, and passes the return value of main() when it does so! -- Dave Levenson Westmark, Inc. A node for news. Warren, NJ USA {rutgers | clyde | mtune | ihnp4}!westmark!dave