在删除“noreturn”关键字后,C 编程语言的 C11 标准(称为最终草案)引入了一个新的“_Noreturn”函数说明符,该说明符指定函数不会返回调用它的函数。如果程序员试图从声明为 _Noreturn 类型的函数返回任何值,则编译器会自动生成编译时错误。
输出:
输出:
// 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 nown");
return 0;
}
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 nown");
return 0;
}
Ready to begin... BYE BYE