_Noreturn 函数说明符用于告诉编译器该函数不会返回任何内容。如果程序内部使用了一些 return 语句,编译器将产生编译时错误。
#include<stdio.h> main() { printf("The returned value: %d", function); } char function() { return 'T'; //return T as character }
The program terminates abnormally [Warning] function declared 'noreturn' has a 'return' statement
现在,如果它是一个普通函数,它将正常工作。
#include<stdio.h> int function() { return 86; //try to return a value } main() { printf("The returned value: %d", function()); }
The returned value: 86