_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.

CategoryFunction-related
KindKeyword / Statement
C standardC11

📝 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 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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏