__attribute__((noreturn))的用法
外文地址:http://www.unixwiz.net/techtips/gnu-c-attributes.html
__attribute__ noreturn
表示没有返回值
This attribute tells the compiler that the function won't ever return, and this can be used to suppress errors about code paths not being reached. The C library functions abort() and exit() are
both declared with this attribute:
这个属性告诉编译器函数不会返回,这可以用来抑制关于未达到代码路径的错误。 C库函数abort()和exit()都使用此属性声明:
extern void exit(int) __attribute__((noreturn));
extern void abort(void) __attribute__((noreturn));
Once tagged this way, the compiler can keep track of paths through the code and suppress errors that won't ever happen due to the flow of control never returning after the function call.
In this example, two nearly-identical C source files refer to an "exitnow()" function that never returns, but without the __attribute__tag, the compiler issues
a warning. The compiler is correct here, because it has no way of knowing that control doesn't return.
$ cat test1.c
extern void exitnow(); int foo(int n)
{
if ( n > 0 )
{
exitnow();
/* control never reaches this point */
}
else
return 0;
} $ cc -c -Wall test1.c
test1.c: In function `foo':
test1.c:9: warning: this function may return with or without a value
But when we add __attribute__, the compiler suppresses the spurious warning:
$ cat test2.c
extern void exitnow() __attribute__((noreturn)); int foo(int n)
{
if ( n > 0 )
exitnow();
else
return 0;
} $ cc -c -Wall test2.c
no warnings!
__attribute__((noreturn))的用法的更多相关文章
- GUN C/C++ __attribute__ 用法 转
http://blog.csdn.net/mydo/article/details/3738336 GNUC的一大特色(却不被初学者所知)就是__attribute__机制.__attrib ...
- iOS宏和__attribute__
本文目录 iOS宏的经典用法 Apple的习惯 __attribute__ iOS宏的经典用法 1.常量宏.表达式宏 #define kTabBarH (49.0f) #define kScreenH ...
- __attribute__
转来的: http://www.cnblogs.com/astwish/p/3460618.html __attribute__ 你知多少? GNU C 的一大特色就是__attribute__ 机制 ...
- __attribute__ 你知多少?
GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属性(Function Attribute ).变量属性(Variable Attribute )和 ...
- __ATTRIBUTE__ 你知多少?【转】
转自:http://www.cnblogs.com/astwish/p/3460618.html GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属 ...
- __attribute__你知多少(转)
转自:http://www.cnblogs.com/astwish/p/3460618.html GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属 ...
- C之attribute用法
GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属性(Function Attribute ).变量属性(Variable Attribute )和 ...
- __attribute__的一些相关属性
__attribute__((format())) 这个format有3个参数. int my(NSString *str,NSString *str1,NSArray*str2,...) __at ...
- __ATTRIBUTE__ 知多少?
GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属性(Function Attribute ).变量属性(Variable Attribute )和 ...
随机推荐
- 百度地图 创建 自定义控件(vue)
1.组件代码 Bmap.vue <!-- 离线地图 组件 --> <template> <div id="map" :style="styl ...
- python(15)- 装饰器及装饰器的使用
装饰器 1.无参数 2.函数有参数 3.函数动态参数 4.装饰器参数 装饰器的应用 下面题目同http://www.cnblogs.com/xuyaping/p/6679305.html,只不过加了装 ...
- 关于Win8 用不了USB转串口驱动
win8系统必需要关闭设备驱动自己主动更新,否则联网更新的驱动是用不了的.操作过程例如以下: 打开控制面板,搜索"设备".更改设备安装设置 watermark/2/text/aHR ...
- 服务管理-DHCP、NTP、SSH
DHCP协议的作用及原理 1.寻找server 当DHCP客户端第一次登陆网络的时候,也就是客户发现本机上没有任何ip资料设定,他会向网路发送一个dhcpdiscover封包.因为客户端还不知道自己属 ...
- Cisco策略路由(policy route)精解(转载)
原文:http://www.guanwei.org/post/Cisconetwork/07/Cisco-policy-route_8621.html 注:PBR以前是CISCO用来丢弃报文的一个主要 ...
- 继续聊WPF——获取ComboBox中绑定的值
千万不要认为WPF中的数据绑定会很复杂,尽管它的确比Winform程序灵活多了,但其本质是不变的,特别是ComboBox控件,我们知道在Winform中对该控件的有两个专为数据绑定而设定的属性——Di ...
- 2809: [Apio2012]dispatching
2809: [Apio2012]dispatching Time Limit: 10 Sec Memory Limit: 128 MB Submit: 3102 Solved: 1641 [Sub ...
- 九度OJ 1125:大整数的因子 (大数运算)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:974 解决:494 题目描述: 已知正整数k满足2<=k<=9,现给出长度最大为30位的十进制非负整数c,求所有能整除c的k. ...
- Refusing to install package with name “XXXX”
我的执行步骤 我创建了一个名叫express的文件夹,想在这个工程中学习express 进入该文件夹,执行npm init来初始化package.json文件,一直回车. 我们会发现当前文件夹多了一个 ...
- git 的安装
git在开发中已经成了必备工具了,我们来看看git在各个平台上的安装 1.Linux上安装git $sudo apt-get install git 2.mac上安装 1)homebrew安装git ...