__attribute__ noreturn 用法
来源:互联网 发布:淘淘汽配网上商城源码 编辑:程序博客网 时间:2024/05/20 19:46
外文地址: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.cextern void exitnow();int foo(int n){ if ( n > 0 ){ exitnow();/* control never reaches this point */} else return 0;}$ cc -c -Wall test1.ctest1.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.cextern void exitnow() __attribute__((noreturn));int foo(int n){ if ( n > 0 ) exitnow(); else return 0;}$ cc -c -Wall test2.cno warnings!
- __attribute__((noreturn))的用法
- __attribute__ noreturn 用法
- __attribute__ noreturn
- __attribute__ noreturn
- __attribute__ ((noreturn))得使用
- __declspec(noreturn)的用法
- __declspec(noreturn)的用法
- __attribute__用法
- __attribute__ 用法
- GNU C __attribute__ 用法
- __attribute__用法小结
- __attribute__((pack))的用法
- __attribute__ ((packed))用法
- 函数属性__attribute__的用法
- __attribute__的一些小用法
- GUN C/C++ __attribute__ 用法
- __attribute__ ((packed)) 的作用 用法
- Object-c __attribute__((overloadable))) 用法
- 安卓集成webApp,方法互调及集成两个webApp之间的跳转
- axis2 webservice
- 练习题 用到了 listview多条目 GridView+listview 侧滑 ,TabLayout .PullToRefreshListView PullToRefreshScrollV
- BaseAdapter适配器
- 利用贝叶斯分类器对fetch_20newsgroups数据集进行分类
- __attribute__ noreturn 用法
- Fragment+GridView+轮播图
- DarwinStreamingSrvr5.5.5-Windows安装时报错问题解决
- 从AFX_MANAGE_STATE(AfxGetStaticModuleState())说起
- 每日一练20171019
- pyhton 中文汉字转拼音-xpinyin
- 嵌入式linux开发环境搭建相关
- Filter、FilterChain、FilterConfig源码翻译
- 量子纠缠(三)——波尔和爱因斯坦之争