c++ - GCC: "__unused__"与变量属性中的 "unused"

标签 c++ gcc compiler-warnings

根据 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 of aligned.

包含双下划线的标识符 (__) 保留给实现。因此,任何用户程序都不能合法地将它们定义为宏。

关于c++ - GCC: "__unused__"与变量属性中的 "unused",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27139518/

相关文章:

c++ - 如何正确解除分配 C++ vector ?

c - 为什么 asm 由 gcc mov 生成两次?

c - 警告 "format not a string literal and no format arguments"未出现在最新的 gcc 版本中

c++ - UAC是否可以在不启动另一个进程的情况下提升一个进程

c++ - 虚函数和模板冲突

c++ - 如何使 QtLinguist 随 Qt 5.9.1 一起工作?

c - 如何解决 VSCode 中的“"Could not find the task ' gcc build active file.”错误?

python - 安装脚本退出并出现错误 : command 'x86_64-linux-gnu-gcc' failed with exit status 1

intellij-idea - IntelliJ IDEA "Overrides method"警告与 Java 8 lambda 表达式

c++ - clang 中的 Clang : no warning with -Wdangling-gsl and curly braces initialization, 错误?