K
Keith Thompson
Ralph Spitzner said:Keith Thompson wrote:
[...]No, not arguing about the _Noreturn statement itself (which might beThe meaning of 'return' isn't a matter of perception.
Are you arguing that the use of `_Noreturn` in my example is incorrect,
or that it should mean something other than what the standard says it
means?
making things easier for the optimizer), but rather about that a
function must end somehow, be it by a kill -9.
Unless you're running on bare metal something will catch that
termination and clean up,therefore having noticed a 'return'
Maybe that noreturn statement is just a little bit too abstract,
or the term is just strange to me.
The compiler could just grok it by seeing something like
for(;
or
while(1)
If you want to discuss something other than "noreturn", perhaps you
could make it clearer that you're not talking about "noreturn". Your
initial followup in this thread sounded very much like you were
disagreeing with what "noreturn" means.
If you'd like to understand what "noreturn" means, grab a copy of
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf and search for
"noreturn" (including references to the "_Noreturn" keyword).
One potentially tricky aspect is that any use of the word "shall" that's
not within a constraint means that violating the requirement causes
undefined behavior. For example, if I write:
#include <stdio.h>
#include <stdnoreturn.h>
noreturn int foo(void) {
return 42;
}
int main(void) {
int result = foo();
printf("result = %d\n", result);
return 0;
}
the compiler is not required to diagnose the error -- but neither is it
required to generate any code for the printf() call. (And with gcc, it
can produce no output or crash with a segmentation fault, depending on
the optimization level).