There is a difference between the two.
When the attribute, __unused
, appears before the star, it decorates the primary type of the entire declaration list. All variables will be "unused":
__unused NSString *foo, *bar; // OK. All variables are unused in the statement.
NSString __unused *foo, *bar; // OK
But when placed after the *
, it will only apply to the first variable:
NSString * __unused foo, *bar; // Unused variable 'bar'
I prefer NSString * __unused foo;
because it seems more clear to me and won't hide the rare case when I declare multiple variables in one statement.
The GCC Attribute Syntax reference mentions it in Section 6.31:
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.