From GCC:属性语法 https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax:
在使用单个说明符和限定符列表的多个标识符的声明中,属性说明符列表可以紧邻在逗号分隔的声明符列表中的声明符(第一个除外)之前出现。此类属性说明符仅适用于它们出现在其声明符之前的标识符。例如,在
__attribute__((noreturn)) void d0 (void),
__attribute__((format(printf, 1, 2))) d1 (const char *, ...),
d2 (void);
the noreturn
属性适用于声明的所有函数; format 属性仅适用于d1
.
更正:正如评论所指出的,我之前的结论是错误的。我没有注意到除了第一个之外 part.
修正结论:
In both
int __attribute__((used)) a, b, c;
and
__attribute__((used)) int a, b, c;
该属性适用于所有 a、b 和 c。
但如果是:
int a, __attribute__((used)) b, c;
该属性将应用于b
only.