Functions that do not return

suggest change

Use the standard [[noreturn]] attribute in C23 to declare that a function does not return to its caller. This lets the implementation diagnose mistakes and optimize control flow.

#include <stdio.h>
#include <stdlib.h>

[[noreturn]] void fail(const char *message)
{
    fputs(message, stderr);
    fputc('\n', stderr);
    exit(EXIT_FAILURE);
}

Reaching the end of a function declared [[noreturn]], or executing a return statement in it, results in undefined behavior.

C11 through C17 use the _Noreturn function specifier. Those versions also provide a noreturn convenience macro in <stdnoreturn.h>. Both _Noreturn and <stdnoreturn.h> are deprecated in C23; prefer the attribute in new code.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents