Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

<stdnoreturn.h> — functions that do not return

The <stdnoreturn.h> header defines noreturn as _Noreturn. It is obsolescent in C23; new code can use [[noreturn]] without this header.

Version: C23; repository compiler flag, production runtime not attested

Syntax

#include <stdnoreturn.h>
noreturn void stop(void);

<stdnoreturn.h> defines the noreturn macro, expanding to the _Noreturn function specifier. An annotated function must not return to its caller; violating this promise causes undefined behavior. A void return type alone provides no such guarantee.

In C23, the header, macro, and specifier are obsolescent but remain available. For new code, use [[noreturn]] void stop(void); without this header. The attribute does not terminate execution automatically.

The example demonstrates the older spelling: exit(EXIT_SUCCESS) terminates the program instead of returning from stop.

Examples

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

noreturn void stop(void)
{
    puts("Done");
    exit(EXIT_SUCCESS);
}

int main(void)
{
    stop();
}

Result

Done

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources