Does __attribute__ apply to all the variables in a declaration?

From GCC: Attribute-Syntax:

An attribute specifier list may appear immediately before a declarator (other than the first) in a comma-separated list of declarators in a declaration of more than one identifier using a single list of specifiers and qualifiers. Such attribute specifiers apply only to the identifier before whose declarator they appear. For example, in

__attribute__((noreturn)) void d0 (void),
     __attribute__((format(printf, 1, 2))) d1 (const char *, ...),
      d2 (void);

the noreturn attribute applies to all the functions declared; the format attribute only applies to d1.


Correction: As the comment points out, my previous conclusion is incorrect. I didn’t notice the other than the first part.

Modified conclusion:

In both

int __attribute__((used)) a, b, c;

and

__attribute__((used)) int a, b, c;

The attribute applies to all a, b, and c.

But if it were:

int a, __attribute__((used)) b, c;

The attribute would apply to b only.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)