Path: utzoo!mnetor!uunet!husc6!hao!oddjob!gargoyle!ihnp4!homxb!mtuxo!mtune!codas!cpsc6a!cpsc6b!crs From: crs@cpsc6b.cpsc6a.att.com (Chris (Batches? We don't need no steenking batches!) Seaman) Newsgroups: comp.lang.c Subject: return (0) vs. exit(0) from main(). Message-ID: <441@cpsc6b.cpsc6a.att.com> Date: 31 Dec 87 18:58:53 GMT Organization: AT&T (CPSC), Oakland, CA Lines: 28 I have been following the discussion of the return vs. exit controversy, and have a couple of observations: 1) If exit is perferred over return, the why does everyone agree that crt0 calls main, and then calls exit? Whether it checks the return value from main is not my question. The point is crt0 assumes that main will return control to it under normal circumstances. 2) I work on an AT&T 3B15, an IBM PC (Turbo C and Microsoft C 5.0), and an Amiga 1000 (Manx 3.4a). All these environments *expect* main to return to crt0. Of course, if you want to return a non-zero value to your operating system, you should use exit. *But*, if a program exits normally, it should be returning zero, and none of the implementations I've seen discussed here would prevent that when using return (from main). 3) On the AT&T 3B15, if I write code that *does not* use return from main as the logical end of the function (meaning, when all goes well), but uses exit instead, lint complains that I am returning a random value to the calling environment. -- Chris Seaman | o\ /o crs@cpsc6a.att.com | || See "Attack of the Killer Smiley"! ..!ihnp4!cpsc6a!crs | \vvvvvv/ Coming Soon to a newsgroup near you! | \____/