4 ms·
> I was kind of surprised about the fact that there was no warning about the missing return from main(). Normally, I'd expect the compiler to complain that a su
by jcranmer 5y ago
> I was kind of surprised about the fact that there was no warning about the missing return from main(). Normally, I'd expect the compiler to complain that a supposed int returning function does not return anything, because that would normally be undefined behaviour.
If main() returns without a return statement, it is defined to return 0 by the specification. (§5.1.2.2.3 of http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2596.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2596.pdf, but this hasn't changed in quite some time).
- quietbritishjim 5y agoThe article already explains this. What you said is only true in C99 (and they indeed show the return value of the overall program is 0 when compiled in that mode). In C89 it's undefined behaviour, so a warning when you do this would be very sensible.