_Noreturn Declare functions that do not return
_Noreturn Declare functions that do not return
C11's _Noreturn marks nonreturning functions. It is a contract, not termination; returning is undefined, and code after a call cannot be assumed to run.
| Category | Function-related |
|---|---|
| Kind | Keyword / Statement |
| C standard | C11 |
📝 Syntax
_Noreturn void die(void);
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
Exiting normally
ℹ️ Info finish calls exit(EXIT_SUCCESS), so standard output is flushed during normal termination and the example text is observable. The return 0 at the end of main is never executed; it merely retains a complete structured return path.
🏷️ Related function keywords
📚 Related Tutorials
❓ FAQ
QWhat happens if a _Noreturn function eventually returns?
AThat violates its contract not to return to the caller. If a function declared _Noreturn does return, behavior is undefined, and the compiler may no longer generate normal code for paths after the call.
QAre _Noreturn and exit the same thing?
ANo. _Noreturn is a specifier describing function control flow and does not itself terminate the program. exit is a standard library function that terminates the program and is often called ultimately by a _Noreturn function.
QCan _Noreturn be used on a function that might return normally?
AIt should not. Any path that returns to the caller violates the nonreturning contract. Even if current tests never take that path, _Noreturn must not be added casually as an ordinary optimization hint.