一、简介
__attribute__ 是个编译器指令,告诉编译器声明的特性,或者让编译器进行更多的错误检查和高级优化。
attribute 可以设置函数属性(Function Attribute)、变量属性(Variable Attribute)和类型属性(Type Attribute)。
__attribute__ 是GCC的特性,LLVM借鉴过来,又对其进行了扩展。
当__attribute__ 用于修饰对象时,它就如同C 语言语法体系结构的类型限定符,跟const , volatile , restrict 等属一类。
当__attribute__ 用于修饰函数时,它就相当于一个函数说明符,跟inline,Noreturn 属同一类。
当__attribute_ 用于修饰一个结构体,联合体或者枚举类型,该限定符只能放在类型标识符之前。
| 函数属性(Function Attribute) | 类型属性(Type Attributes) | 变量属性(Variable Attribute) | Clang特有的 |
|---|---|---|---|
| noreturn | aligned | alias | availability |
| noinline | packed | at(address) | overloadable |
| always_inline | bitband | aligned | |
| flatten | deprecated | ||
| pure | noinline | ||
| const | packed | ||
| constructor | weak | ||
| destructor | weakref(“target”) | ||
| sentinel | section(“name”) | ||
| format | unused | ||
| format_arg | used | ||
| section | visibility(“visibility_type”) | ||
| used | zero_init | ||
| unused | |||
| deprecated | |||
| weak | |||
| malloc | |||
| alias | |||
| warn_unused_result | |||
| nonnull | |||
| nothrow (不抛出C++ 异常) |
二、语法
__attribute__ 书写特征是:__attribute__ 前后都有两个下划线,并切后面会紧跟一对原括弧,括弧里面是相应的__attribute__ 参数。
attribute 语法格式为: __attribute__ ((attribute-list))
三、示例
ref:
https://www.jianshu.com/p/e2dfccc32c80
https://blog.csdn.net/weaiken/article/details/88085360
https://blog.csdn.net/qlexcel/article/details/92656797
https://www.cnblogs.com/embedded-linux/p/5801999.html
最后
以上就是真实小笼包最近收集整理的关于C语言__attribute__的使用一、简介二、语法三、示例的全部内容,更多相关C语言__attribute__内容请搜索靠谱客的其他文章。
发表评论 取消回复