Path: utzoo!mnetor!uunet!husc6!hao!oddjob!gargoyle!ihnp4!laidbak!daveb From: daveb@laidbak.UUCP (Dave Burton) Newsgroups: comp.lang.c Subject: Re: exit(main(argc,argv,env)); Message-ID: <1284@laidbak.UUCP> Date: 18 Dec 87 06:13:14 GMT References: <10875@brl-adm.ARPA> Reply-To: daveb@laidbak.UUCP (Dave Burton) Organization: is pretty bad/My method of Lines: 29 In article <10875@brl-adm.ARPA> ADLER1%BRANDEIS.BITNET@CUNYVM.CUNY.EDU writes: >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 Actually, "main(...)" DOES give exit() an integer argument. Remember, any function without a type declaration in C is implicitly a function returning int. This line of code simply starts the C program at the symbol "main", passing the usual arguments to it. When main returns, an integer value is pushed on the stack for the exit(). I don't have the emacs source, so I don't know exactly what main() returns to exit(). If no explicit return is given, the value returned is undefined. If main() quits with an exit() call, I believe the exit(main()) will get the argument from the main(){ ... exit(x); }. -- --------------------"Well, it looked good when I wrote it"--------------------- Verbal: Dave Burton Net: ...!ihnp4!laidbak!daveb V-MAIL: (312) 505-9100 x325 USSnail: 1901 N. Naper Blvd. #include Naperville, IL 60540