🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9441

Re: functions that don't return

#9441
From: karl
Date: Tue, 30 Sep 1986 16:25
29 lines
2156 bytes
hadron!jsdy (Joe Yao) writes:
>Using 'return' from main() is the preferred way to exit according
>to System V lint (which complains otherwise).

The reason is simply that lint doesn't know about exit() -- it's just another
function as far as it knows.  The warning is not in any way an endorsement
of return over exit, as lint will be equally happy if you put a goto at the
bottom of main() and call exit() in the middle somewhere.

>I've preferred it myself, for years before, because I've viewed exit() as a
>glitch in a smooth mental model of the invocation and return of routines.

I used to prefer return for the same reasons (actually I preferred exit()
before that, because it works even if your local crt0 ignores the result of
main -- as ours did for a while).  Now I've reverted to exit(), because I
consider it a better model for error handling: "fprintf(stderr, usage); \
exit(1);" is more meaningful to me than "... return (1);" and won't break
if the code segment moves into a subroutine.  At the bottom of main(), I now
tend to use exit() again (throwing in a /*NOTREACHED*/ and cussing under my
breath), for reasons I can't explain well.

There are three possible models for the crt0/main interface:  main() could be
int ("exit(main())"), void ("main(); exit(0)"), or dead ("main(); HALT").  I
kind of like the last idea; it requires the user to explicitly call exit(),
but it makes all main programs equivalent.  (Including those which neither
return nor exit, for which the declaration "int main()" looks silly.)

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint
Technical Details
Message-ID: <86900070@haddock>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!caip!think!ima!haddock!karl
References: <584@hadron.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!caip!think!ima!haddock!karl
From: karl@haddock
Newsgroups: net.lang.c
Subject: Re: functions that don't return
Message-ID: <86900070@haddock>
Date: Tue, 30-Sep-86 12:25:00 EDT
Article-I.D.: haddock.86900070
Posted: Tue Sep 30 12:25:00 1986
Date-Received: Wed, 1-Oct-86 06:19:19 EDT
References: <584@hadron.UUCP>
Lines: 29
Nf-ID: #R:hadron.UUCP:584:haddock:86900070:000:1610
Nf-From: haddock!karl    Sep 30 12:25:00 1986