A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/algorithm/../algorithm/../../cpp/../c/language/noreturn.html below:

_Noreturn function specifier (since C11)(deprecated in C23)

Specifies that the function does not return to its point of invocation.

[edit] Syntax _Noreturn function_declaration (since C11)(deprecated in C23) [edit] Explanation

The _Noreturn keyword appears in a function declaration and specifies that the function does not return by executing the return statement or by reaching the end of the function body (it may return by executing longjmp). If the function declared _Noreturn returns, the behavior is undefined. A compiler diagnostic is recommended if this can be detected.

The _Noreturn specifier may appear more than once in the same function declaration, the behavior is the same as if it appeared once.

This specifier is typically used through the convenience macro noreturn, which is provided in the header <stdnoreturn.h>.

_Noreturn function specifier is deprecated. [[noreturn]] attribute should be used instead.

The macro noreturn is also deprecated.

(since C23) [edit] Keywords

_Noreturn

[edit] Standard library

The following functions are noreturn in the standard library:

[edit] Example
#include <stdio.h>
#include <stdlib.h>
#include <stdnoreturn.h>
 
// causes undefined behavior if i <= 0
// exits if i > 0
noreturn void exit_now(int i) // or _Noreturn void exit_now(int i)
{
    if (i > 0)
        exit(i);
}
 
int main(void)
{
    puts("Preparing to exit...");
    exit_now(2);
    puts("This code is never executed.");
}

Output:

[edit] References
[edit] See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4