Must main return a value?

Norman Diamond diamond at jit533.swstokyo.dec.com
Fri Jun 28 15:58:40 AEST 1991


In article <7830001 at hpwrce.HP.COM> walterm at hpwrce.HP.COM (Walter Murray) writes:
>Is the following program strictly conforming?
>   int main(void) { return; }
>Many people have written that the main function must return a value.
>I can't find such a requirement in the Standard.  I have read 2.1.2.2.3
>and 3.6.6.4.  Am I missing something?

For the effect of the program to be defined, the main function must return
a value.  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.

OK, if you don't want your program to send a small nuclear device at your car,
the main function must return a value.  (2.1.2.2 neither allows nor disallows
this extreme an effect; 3.6.6.4 allows it.)
--
Norman Diamond       diamond at tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
Permission is granted to feel this signature, but not to look at it.



More information about the Comp.std.c mailing list