[小技巧] gcc attribute error 属性小试
来源:互联网 发布:淘宝最火的女装店 编辑:程序博客网 时间:2024/04/29 00:51
gcc __attribute__ 里有一个属性是 error 可以用于编译时报错。
参考:
https://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Function-Attributes.html
error ("
message")
__builtin_constant_p
and inline functions where checking the inline function arguments is notpossible throughextern char [(condition) ? 1 : -1];
tricks. While it is possible to leave the function undefined and thus invokea link failure, when using this attribute the problem will be diagnosedearlier and with exact location of the call even in presence of inlinefunctions or when not emitting debugging information. 写了一个简单的示例:
extern void foo(void) __attribute__((error("build failed"))); #define FOO 0int main(void){if(FOO == 0)foo();return 1;}
这里由于 FOO == 0 判断成立,所以会在编译时候直接报下面的错误:
/tmp/helloworld.c: In function 'main':
/tmp/helloworld.c:7:6: error: call to 'foo' declared with attribute error: build failed
这里文件名/行号和错误的信息 "build failed" 都会输出。
另外,内核的 BUILD_BUG() 这个宏也是用了GCC这个属性。
0 0
- [小技巧] gcc attribute error 属性小试
- GCC 小技巧
- gcc的小技巧
- linux编程gcc小技巧
- [小技巧] gcc 编译选项-###
- VS项目-属性小技巧
- 100个gcc小技巧项目
- javascript小技巧&&JavaScript[对象.属性]集锦
- javascript小技巧&&JavaScript[对象.属性]集锦
- javascript小技巧&&JavaScript[对象.属性]集锦
- javascript小技巧&&JavaScript[对象.属性]
- javascript小技巧&&JavaScript[对象.属性]集锦
- javascript小技巧&&JavaScript[对象.属性]
- javascript小技巧&&JavaScript[对象.属性]集锦
- javascript小技巧&&JavaScript[对象.属性]集锦
- javascript小技巧&&JavaScript[对象.属性]集锦
- javascript小技巧&&JavaScript[对象.属性]集锦
- VC编程小技巧之属性页
- 安卓对话框之----多选框(CheckBox)
- Android 四大组件学习之ContentProvider三
- JavaScript相关
- 论文参考文献
- UISegmentedControl和UIPickerView
- [小技巧] gcc attribute error 属性小试
- cookie与session
- spfa 最短路径
- 图像处理------特殊灰度算法技巧
- iOS 与 Android 生命周期对比
- Android -- EventBus
- fget函数读取一行数据,非二进制文件 -- linux
- CTP多点触摸协议
- java并发编程实战 第五章(2)合并任务的结果