4 ms·
> Side note: even though we can't return, main is the exception to the rule that reaching the closing } of a function returning non-void is verboten, Isn't it
by jnxx 4y ago
> Side note: even though we can't return, main is the exception to the rule that reaching the closing } of a function returning non-void is verboten,
Isn't it legal to fall of the end of the end of a non-void function, only just defined as UB to use the return value?
- tedunangst 4y agoCorrect. > If the } that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined.
- planede 4y agoInterestingly C++ makes this UB. > Otherwise, flowing off the end of a function other than main or a coroutine ([dcl.fct.def.coroutine]) results in undefined behavior. https://timsong-cpp.github.io/cppwp/n4868/stmt.return#2.sentence-9 https://timsong-cpp.github.io/cppwp/n4868/stmt.return#2.sent... edit: This also manifests in compiler optimizations, at least in gcc https://godbolt.org/z/GhxjdWqGb https://godbolt.org/z/GhxjdWqGb