Re:C, C++, x86/x64 assembly: The case of forgotten return
by maxlybbert on Thursday December 13, 2018 @03:46PM
(#18675924)
I’m sure that rule comes from the time when “void” didn’t exist, so functions were defined to return int, but nobody ever bothered to actually return anything.
[ Parent
| on HN ]
Re:C, C++, x86/x64 assembly: The case of forgotten return
by chartreusek on Thursday December 13, 2018 @05:23PM
(#18676676)
It's definitely there to retain some backwards compatibility with existing K&R C programs. Though it does still somewhat exist in the C11 standards.
From 6.9.1 - "If the } that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined"
Though 6.8.6.4 also says "A return statement without an expression shall only appear in a function whose return type is void"
So it seems like a non-void function hitting the end of the block without a return statement is allowed (provided the value isn't used). But having a "return;" in that function would not be in C11.