K
Keith Thompson
Jordan Abel said:Some of the people in this group have radical ideas about the semantics
of main() in particular. I think Peter Nilsson's claim (which I disagree
with) is that even without an exit statement, main doesn't need to
return a value, since main's caller is outside the scope of the C
standard.
It depends on what you mean by "doesn't need to". In C90, falling off
the end of main returns an arbitrary status to the environment. (I
don't have my C90 standard handy so I don't remember whether it's
unspecified, undefined, or something else.) This doesn't affect the
execution of the program itself, just what happens after the program
finishes.
In C99, though, falling off the end of main is equivalent to "return
0;" (a bad rule IMHO, but there it is), so it's no longer even
possible for main not to return a value. (You could return the value
of an uninitialized variable, but that invokes undefined behavior as
soon as you evaluate the variable, before the return is even
executed.)