@Tuomo_T understandably. However, int main(void)
is not a void
function. It has a specified return type. C99 is pretty strict about matching of returns with the specified return type, requiring no expression if the return type is āvoidā. The case at hand is if a function drops through the end of its body without any return. From Harbison & Steele ed.5,
If program control reaches the end of a function body without encountering a return
statement, then the effect is as if a return
statement with no expression were executed. If the function has a non-void
return type, then the behavior is undefined.
That appears to be the gap that allows implementation-dependent implementations of main to imply return 0;
although one should not rely on it.
Hereās a consideration that bothers me more. It is possible to invoke a non-void
function and do so in a statement that does not employ a returned value. This happens all the time in the case of int
-returning functions where the invoking code is essentially ignoring any returned result because it is the side-effect of the operation that is all that matters (i.e., printf and such). This is so commonplace, compilers donāt warn about it. Is the same true of other numeric returns, how about non-numeric returns (i.e., returning a struct
value)? These are all cases of generally-permissible discarded values. I would expect some sort of warning in some cases, at least as valuable as ones about slack bytes in structs
PS: I only have information as recent as C99. I donāt know if later revisions of ISO C Language have altered any of this.