Subject: Re: main return...
To: Ty Sarna <>
From: Charles M. Hannum <>
List: current-users
Date: 03/28/1996 04:49:02
   But my point is, void main() is (and I wish I could think of the Latin
   phrases for these) "wrong because it's prohibited", not "wrong in and of

That's *not* true.  The C startup code on every ANSI-compliant system
expects main to return int.  People seem to be assuming that the
return type simply doesn't matter.  This is wrong for several reasons:

1) Nothing prevents (nor should anything prevent) the function *entry*
sequence from depending on the return type in some fashion.

2) Nothing prevents (nor should anything prevent) the return type from
being put on a stack, which would cause an incorrect declaration to

3) Nothing prevents (nor should anything prevent) the compiler from
checking return types and prototypes to insure that the supplier and
the users of each function agree.  In fact, this is a good feature.

4) Nothing prevents (nor should anything prevent) exit() from being
implemented as a non-local jump to the end of main(), in which case
all of the above is relevant even if `main never returns'.

Believe it or not, most of the rules in ANSI C are *not* arbitrary;
they're there either because `that's how C has always been' or because
it's unreasonable to expect all implementations to work in a
particular way.

(e.g.  Requiring a NULL pointer to be all 0 bits would break on
existing implementations; hence ANSI was very careful only to require
certain conversion properties between 0 and NULL.)