Assume this context:
int main(void) { return; }
and hosted version.
Please note that void main() not strictly forbidden (implementation is allowed to resolve it), but return; will be completely correct in such a definition of main .
The first is return; , obviously, is a violation of the restriction. It violates N1570 6.8.6.4p1:
A return without an expression should only appear in a function whose return type is void .
(This was not a violation of the restriction in C90, which was changed to C99.)
The standard requires that the compiler issue at least one diagnostic for any program that contains a violation of a restriction rule or syntax. After that, it can continue to generate an executable file (if the diagnosis is a non-fatal warning).
It is unclear whether there is a general rule that programs with violation of restrictions have undefined behavior. The standard does not say so explicitly. He defines "restriction" as
a restriction, syntactic or semantic, with which to interpret the presentation of language elements
My own interpretation is that if the restriction is violated, then there is no valid interpretation, and therefore the behavior is undefined, but there are some who disagree. I would like to see an explicit statement about this in the future standard.
I believe that the wording of the C-standard is really ambiguous in this matter.
Without such a general rule, it is not clear that the behavior is undefined. After specifying a restriction that this code violates, the standard continues to define the semantics of the return :
The return terminates the current function and returns control to its caller.
This description may make sense even if there is a violation of the restriction. It is reasonable to assume, although not entirely clear, that return; equivalent to reaching the closing } , which is equivalent to return 0; (This is a special case rule for main ; N1570 5.1.2.2. 3).
On the other hand, it is not 100% clear that the description is unambiguous. The argument is that return; equivalent to achieving closure } , is particularly weak. Thus, even in the absence of a general rule, it can be argued that the behavior is undefined by skipping (there is no definition of behavior).
return; is clearly a violation of the restriction, and in my opinion, it has undefined behavior if the implementation creates an executable file. Of course, the corresponding compiler is also allowed to completely abandon the program; in this case, he has no behavior at all.
Bottom line: significantly easier to change return; on return 0; than to answer this question.
I urge other language advocates to refute this answer. I have made fairly intrinsically contradictory arguments here that this should not be too complicated.