Path: utzoo!mnetor!uunet!husc6!hao!noao!arizona!naucse!sbw From: sbw@naucse.UUCP (Steve Wampler) Newsgroups: comp.lang.c Subject: Re: exit(main(argc,argv,env)); Message-ID: <526@naucse.UUCP> Date: 18 Dec 87 17:02:36 GMT References: <10875@brl-adm.ARPA> <1451@houdi.UUCP> Organization: Northern Arizona University, Flagstaff, AZ Lines: 21 Summary: main not the first called 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? The key is probably that the statement was found in crt0.c. On all the systems I'm familiar with, the 'main' function is not called directly by the system - instead the system invokes a 'startup' routine that opens standard files, munges the environment a bit, and then calls 'main'. I'll bet the above code was in a routine 'start' or 'Start'. Most of the languages I'm familiar with do this - I can remember rewriting the FORTRAN startup routine on a CDC 6400 to process ratfor more cleanly, patterned after an approach some friends used on a DEC-10.