14.1.2.15 noreturn
A few standard library functions, such as abort and exit, cannot return. The compiler knows this automatically. Some programs define their own functions that never return. You can declare them noreturn to tell the compiler this fact. For example:
void fatal (int i) __attribute__ ((noreturn));
void
fatal (int i)
{
/* Print error message. */
exit (1);
}
The noreturn
keyword tells the compiler to assume that
fatal
cannot return. It can then optimize without regard to what
would happen if fatal
ever did return. This makes slightly better code.
It also helps avoid spurious warnings of uninitialized variables.
It does not make sense for a noreturn
function to have
a return type other than void
.
A noreturn
function will reset if it attempts to
return.