Ever since I realized many years ago, that this doesn\'t produce an error by default (in GCC at least), I\'ve always wondered why?
I understand that you can issue co
It is a constraint violation in c99, but not in c89. Contrast:
c89:
3.6.6.4 The
return
statementConstraints
A
return
statement with an expression shall not appear in a function whose return type isvoid
.
c99:
6.8.6.4 The
return
statementConstraints
A
return
statement with an expression shall not appear in a function whose return type isvoid
. Areturn
statement without an expression shall only appear in a function whose return type isvoid
.
Even in --std=c99
mode, gcc will only throw a warning (although without needing to enable additional -W
flags, as is required by default or in c89/90).
Edit to add that in c89, "reaching the }
that terminates a function is equivalent to
executing a return
statement without an expression" (3.6.6.4). However, in c99 the behavior is undefined (6.9.1).