根据 GCC's own documentation on variable attributes ,声明未使用属性的正确语法是 __attribute__((unused))
。
但是,在许多示例和其他在线代码中,我经常看到 __attribute__((__unused__))
,它们似乎都有效。
在这两种情况下,是否有指定或省略 __
的原因?它有什么区别吗,是否有首选版本?是否存在使用其中一种而不使用另一种可能会导致问题的情况?
想必这同样适用于其他属性参数吗?
最佳答案
在 the very page you linked 的顶部,它告诉你:
You may also specify attributes with ‘
__
’ preceding and following each keyword. This allows you to use them in header files without being concerned about a possible macro of the same name. For example, you may use__aligned__
instead ofaligned
.
包含双下划线的标识符 (__
) 保留给实现。因此,任何用户程序都不能合法地将它们定义为宏。
关于c++ - GCC: "__unused__"与变量属性中的 "unused",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27139518/