__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 )和 ...
随机推荐
- python(36)- 测试题
1.8<<2等于? 32 “<<”位运算 264 132 64 32 16 8 4 2 1 原始位置 0 0 0 0 0 1 0 0 0 想左位移2位 0 0 0 1 0 0 ...
- PHP中多维数组查找某个值是否存在的方法
in_array — 检查数组中是否存在某个值,只是这个方法不能检查多维数组. 所以可以编写类似下面的递归方法来检查多维数组. function deep_in_array($value, $arra ...
- Spring Cloud(十一):Spring Cloud Zuul网关 Filter、熔断、重试、高可用的使用方式
上篇文章主要介绍了Zuul网关使用模式,以及自动转发机制,但其实Zuul还有更多的应用场景,比如:鉴权.流量转发.请求统计等等,这些功能都可以使用Zuul来实现. Zuul的核心 Filter是Zuu ...
- ORACLE 查看表结构
select table_name from user_tables; //当前用户的表 select table_name from all_tables; //所有用户的表 select tabl ...
- window下Jira+SQL Server部署+汉化+破解
网上很多都是jira+mysql部署的文章,由于我现在有需求要用SQL Server数据库,因此就动手试了一下,参考网上许多文章,再加上自己的几次尝试,很快也成功了,分享出来. 全文章节: 一.事前准 ...
- 深入理解Java:注解(Annotation)自己定义注解入门
深入理解Java:注解(Annotation)自己定义注解入门 要深入学习注解.我们就必须能定义自己的注解,并使用注解,在定义自己的注解之前.我们就必须要了解Java为我们提供的元注解和相关定义注解的 ...
- EasyRTMP直播推送效率优化之开源librtmp CPU占用高效率优化
本文转自EasyDarwin开源团队Kim的博客:http://blog.csdn.net/jinlong0603/article/details/52950948 EasyRTMP 前面介绍过Eas ...
- Disruptor学习杂记
慎入,有点乱,只是学习记录,disruptor_2.10.4 1.Disruptor对象有一个EventProcessorRepository对象 2.EventProcessorReposito ...
- Redis C语言操作封装
#ifndef BOYAA_FOURLANDLORD_REDISCLASS_H_20130217 #define BOYAA_FOURLANDLORD_REDISCLASS_H_20130217 #i ...
- [NOIP2011提高组day2]-1-计算系数
1.计算系数 (factor.cpp/c/pas) [问题描述] k n m给定一个多项式(ax+by)^k ,请求出多项式展开后(x^n)*(y^m)项的系数. [输入] 输入文件名为 factor ...