3 ms·
You mention that main not having a return statement is undefined behaviour. While this would be true for most functions the main function is actually a special
by cianlr 9y ago
You mention that main not having a return statement is undefined behaviour. While this would be true for most functions the main function is actually a special case.
If you check section 5.1.2.2.3 - Program termination of the standard doc you linked it says that "reaching the } that terminates the main function returns a value of 0".
This is obviously a super minor nitpick though and I enjoyed the post!
- Lower456 9y agoIt just feels good when you realize the details.
- TheNewAndy 9y agoNote that this is a change in C99 - in C90 spec just says: "A return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument. If the main function executes a return that specifies no value, the termination status returned to the host environment is undefined."
- Joky 9y ago> " the termination status returned to the host environment is undefined." This is still not the same as "undefined behavior" though.