Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!lll-tis!ames!rutgers!mtune!codas!ateng!chip From: chip@ateng.UUCP (Chip Salzenberg) Newsgroups: comp.lang.c Subject: Re: return (0) vs. exit(0) from main(). Message-ID: <145@ateng.UUCP> Date: 4 Jan 88 15:26:06 GMT References: <441@cpsc6b.cpsc6a.att.com> Reply-To: chip@ateng.UUCP (Chip Salzenberg) Organization: A T Engineering, Tampa, FL Lines: 31 In article <441@cpsc6b.cpsc6a.att.com> crs@cpsc6b.cpsc6a.att.com (Chris (Batches? We don't need no steenking batches!) Seaman) writes: > 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. Consider that a function parameter, left undeclared, defaults to type "int". Does this mean that the compiler "expects" you to leave integer function parameters undeclared? Of course not. It is legal to return from main(), but it is neither required nor encouraged. > 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. You should read the lint manual. Try this: main() { ... /* Time to go home. */ exit(0); /* NOTREACHED */ /* Tell lint that exit() doesn't return. */ } -- Chip Salzenberg UUCP: "{codas,uunet}!ateng!chip" A T Engineering My employer's opinions are a trade secret. "Anything that works is better than anything that doesn't." -- me