functions that don't return

guy at sun.UUCP guy at sun.UUCP
Mon Oct 6 06:00:08 AEST 1986


> >>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 at sun.com (or guy at sun.arpa)



More information about the Comp.lang.c mailing list