Open In App
Related Articles

_Noreturn function specifier in C

Improve Article
Improve
Save Article
Save
Like Article
Like

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

Note: 

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

Example:

C




// C program to show how _Noreturn type
// function behave if it has return statement.
#include <stdio.h>
#include <stdlib.h>
 
// With return value
_Noreturn void view()
{
    return 10;
}
int main(void)
{
    printf("Ready to begin...\n");
    view();
 
    printf("NOT over till now\n");
    return 0;
}


Output:

Ready to begin...
After that abnormal termination of program.
compiler error:[Warning] function declared 'noreturn' has a 'return' statement

C




// C program to illustrate the working
// of _Noreturn type function.
#include <stdio.h>
#include <stdlib.h>
 
// Nothing to return
_Noreturn void show()
{
    printf("BYE BYE");
}
int main(void)
{
    printf("Ready to begin...\n");
    show();
 
    printf("NOT over till now\n");
    return 0;
}


Output:

Ready to begin...
BYE BYE

Reference: http://en.cppreference.com/w/c/language/_Noreturn If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 08 Feb, 2023
Like Article
Save Article
Previous
Next
Similar Reads