your image

_Noreturn function specifier in C - GeeksforGeeks

greeksforgeeks
Related Topic
:- C language programming languages

_Noreturn function specifier in C

  • Difficulty Level : Hard
  • Last Updated : 29 Mar, 2019

After the removal of “noreturn” keyword, C11 standard (known as final draft) of C programming language introduce a new “_Noreturn” function specifier that specify that the function does not return to the function that it was called from. If the programmer try to return any value from that function which is declared as _Noreturn type, then the compiler automatically generates a compile time error.

 

 

 

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

Comments