Path: utzoo!mnetor!uunet!husc6!bloom-beacon!athena.mit.edu!wesommer From: wesommer@athena.mit.edu (William Sommerfeld) Newsgroups: comp.lang.c Subject: Re: exit(main(argc,argv,env)); Message-ID: <2058@bloom-beacon.MIT.EDU> Date: 18 Dec 87 17:12:29 GMT References: <10875@brl-adm.ARPA> <1451@houdi.UUCP> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: wesommer@athena.mit.edu (William Sommerfeld) Followup-To: comp.unix.questions Organization: Massachusetts Institute of Technology Lines: 28 This really isn't a C question; it is a UNIX question. > > I was looking through the file crt0.c in the GNU emacs source code and > found the command > > exit(main(argc,argv,env)); > First misconception: exit() is a _function_ in the C library. It happens to be different from other functions in that it never returns control to its caller, but that's just a property of the implementation; there isn't anything in the C compiler which special-cases exit(), or abort(), or any of the other special functions. You don't have to pass it a constant integer. On UNIX, crt0.c happens to be the module which sets up argv, argc, and the environment and then calls main() with the appropriate arguments; it is silently included into the load image by 'cc' when you use it to link a program. Needless to say, it is highly architecture- and OS- dependant. GNU emacs has its own version of crt0.c (with probably hundreds of #ifdefs to account for all sorts of machine dependancies) because it has to be able to dump out a core image of itself containing pre-loaded emacs lisp, and then restart this core image later. - Bill