Must main return a value?

Doug Gwyn gwyn at smoke.brl.mil
Sat Jun 29 09:43:39 AEST 1991


In article <1991Jun28.055840.29919 at tkou02.enet.dec.com> diamond at jit533.enet@tkou02.enet.dec.com (Norman Diamond) writes:
>It does seem strange that the compiler is required to issue a diagnostic for
>a return statement with a value in a void function, but not for the opposite
>mistake.

That's because a vast amount of existing, correct (as of when it was written)
C code is like that.  Before there was a "void" type in C, the effect of a
void-valued function was achieved by coding a (default) int-valued function
and not returning a value.  It's easy for an implementation to deal with this
common practice (either by not worrying about loading the result register or
by building a dummy result value before the function exit code), and as a
widespread officially-sanctioned practice (K&R 1st Ed. had examples), there
was no good reason to disallow this usage.  All that X3J11 had to do along
these lines was to note the obvious fact that an attempt to use a value that
the program hadn't bothered to set up would be nonsensical.



More information about the Comp.std.c mailing list