吾爱程序员:这里有好玩的游戏和软件
当前位置:首页C语言教程 → _Noreturn C 中的函数说明符

_Noreturn C 中的函数说明符

来源:网络 | 更新时间:2022-01-14 22:50:52
在删除“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
 

最新文章

热点资讯

手游排行榜

CopyRight 2020-2030吾爱程序员

鄂ICP备2021004581号-8

本站资源收集于网络,如有侵权请联系我们:35492删除0109@qq.com