liveBook · Manning

_Noreturn

As explained in Modern C

_Noreturn is a C function specifier or attribute indicating that a function does not return to its caller during normal execution.

_Noreturn marks a function that does not return to its caller during normal execution. Use it only for functions with that control-flow behavior; the declaration communicates a fact that helps both readers and the optimizer. section 7.2 section 17.5

A terminating function

_Noreturn void exit(int status);\n\nCalling exit(s) terminates the program, with the same status role as return s in main. Because control never comes back to the caller, exit is declared with _Noreturn. The macro noreturn provides a more readable form through stdnoreturn.h.\n\nTAKEAWAY: _Noreturn describes an execution path that ends without returning to its caller; it does not describe an ordinary void function that happens to return no value. section 7.2

The same property matters for nonlocal control flow:

  • longjmp transfers execution to a target established by setjmp, so the current call does not continue after longjmp. section 17.5
  • In the recursive-descent parser, exceptional conditions call longjmp; the surrounding interface handles them through switch cases selected by setjmp. section 17.5
  • Knowing that longjmp cannot return lets the compiler simplify branch analysis in the function that invokes it. section 17.5

How Modern C covers it

How deep it goes
Defines the property and demonstrates exit and longjmp, but defers broader declaration and compiler details.
Examples
Uses exit’s prototype and a recursive-descent parser that handles exceptional states with longjmp and setjmp.
What it assumes
Assumes familiarity with C functions, return statements, and basic control flow while defining _Noreturn through concrete library examples.
What you can do after
Evaluate/understand when a C function declaration should communicate nonreturning control flow.
How it connects
Connects _Noreturn with exit, main, longjmp, setjmp, and compiler optimization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.