__attribute__
来源:互联网 发布:时代光华管理课程知乎 编辑:程序博客网 时间:2024/05/29 08:42
__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 beingreached. The C library functionsabort() and exit() are bothdeclared with this attribute:
extern void exit(int) __attribute__((noreturn));extern void abort(void) __attribute__((noreturn));
Once tagged this way, the compiler can keep track of paths throughthe code and suppress errors that won't ever happen due to the flowof 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 compileris correct here, because it has no way of knowing that controldoesn'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 spuriouswarning:
$ cat test2.cextern void exitnow() __attribute__((noreturn));int foo(int n){ if ( n > 0 ) exitnow(); else return 0;}$ cc -c -Wall test2.cno warnings!
参考:https://www.cnblogs.com/astwish/p/3460618.html
http://www.unixwiz.net/techtips/gnu-c-attributes.html#noreturn
- __attribute__
- __attribute__
- __attribute__
- __attribute__
- __attribute__
- __attribute__
- __attribute__
- __attribute__
- __attribute__
- __attribute__
- __attribute__
- __attribute__
- __attribute__
- __attribute__
- __attribute__
- __attribute__
- __attribute__
- __attribute__
- 搭建玩live555 RTSP server
- springboot实战之注册interceptor
- Trafodion建表之如何定义分区个数
- JavascriptDom编程艺术学习笔记二
- 按回车键登录功能代码
- __attribute__
- MQ客户端以及服务端安装
- kmp再理解
- JSP中文乱码问题已经解决方法
- 在控制台上输入菱形的边长,打印出菱形
- VINS理论与代码详解3——IMU预积分
- 把可执行jar添加到桌面右键
- Java并发编程:ThreadLocal
- selenium+phantomjs的坑