_Noreturn function specifier in C

CServer Side ProgrammingProgramming

The _Noreturn function specifier is used to tell to the compiler that the function will not return anything. If the program uses some return statement inside it, the compiler will generate compile time error.

Example Code

#include<stdio.h>
main() {
   printf("The returned value: %d\n", function);
}
char function() {
   return 'T'; //return T as character
}

Output

The program terminates abnormally
[Warning] function declared 'noreturn' has a 'return' statement

Now if it is a normal function it will work fine.

Example Code

#include<stdio.h>
int function() {
   return 86; //try to return a value
}
main() {
   printf("The returned value: %d\n", function());
}

Output

The returned value: 86
raja
Published on 09-Apr-2019 09:25:28
Advertisements