Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!panda!genrad!decvax!decwrl!sun!guy From: guy@sun.UUCP Newsgroups: net.lang.c Subject: Re: functions that don't return Message-ID: <7924@sun.uucp> Date: Sun, 5-Oct-86 16:00:08 EDT Article-I.D.: sun.7924 Posted: Sun Oct 5 16:00:08 1986 Date-Received: Tue, 7-Oct-86 20:49:59 EDT References: <584@hadron.UUCP> <86900070@haddock> <1216@bunker.UUCP> <147@bobkat.UUCP> Organization: Sun Microsystems, Inc. Lines: 29 > >>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 think it should be the second choice, main(); exit(0);. The reason > is two fold. First, unless a program specifically bombs off, it > should exit with a happy status. Falling off the bottom of main I > would not consider to be doing anything specific yet the return (and > exit) value will be random. Second, with a random exit status, it > makes the program much less usefull. Make(1) will sometimes work and > sometimes fail, etc. This merely argues against the third alternative, which is clearly wrong (the only program that should exit with a random exit status is the System V Release 2 game "random", when invoked with the "-e" flag, since under those circumstances it's *supposed* to exit with a random exit status). Neither the first and second alternatives permit a correct program to exit with a random status; with the first model, "main" is a function returning "int", so it should always return an "int" value (the S5R2 "lint" will check for this). Since the first alternative is specified by the S5R2 documentation and the ANSI C standard, and is implemented by most other versions of UNIX, it should be the choice unless you manage to convince the ANSI C committee otherwise. -- Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com (or guy@sun.arpa)