Path: utzoo!attcan!uunet!munnari.oz.au!metro!ipso!runxtsa!edward From: edward@runxtsa.runx.oz.au (Edward Birch) Newsgroups: comp.lang.c Subject: Re: return in main is *not* equivalent to exit() (was Re: main() arguments) Message-ID: <1957@runxtsa.runx.oz.au> Date: 11 Jul 90 03:15:15 GMT References: <78627@srcsip.UUCP> <78633@srcsip.UUCP> <25247@mimsy.umd.edu> <833@mwtech.UUCP> Organization: RUNX Unix Timeshare. Sydney, Australia. Lines: 39 > #include > int main(argc, argv) > int argc; char **argv; /* OK so, Chris? :-) */ > { > char buffer[BUFSIZ]; > setbuf(stdout, buffer); > ........ /* some code which produced output */ > return 0; > } > >Note that the bug could be eliminated by replacing `return 0;' >with `exit (0);'. Well, after that the cause for this problem >became obvious to me ... of course, all of you readers out there >in net-world allready know what the problem is, don't you :-) You will find that the real problem is that some how the return address for main has been corrupted. As far as I am concerned return and exit(); are the same thing for "main", in the general case. Please note that "main" is a routine in it's own right and can be called recursively! Hence in the recurive case exit() is explicit. It means terminate now, whereas return ; may not. I think this is what K&R meant at the time. Secondly "main" as the first routine of a program is only a convention most compilers have some other entry point like "start" which sets up the arguments and environment variables etc for "main" and then calls "main" the object code for these modules is stored in /lib/crt0.o . Edward Birch Telex: 10713856 BRHT UUCP: seismo!munnari!runx.oz!edward ACSnet: edward@runx.oz ARPA: edward%runx.oz@seismo.css.gov CSNET: edward@runx.oz