Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC: "__unused__" vs just "unused" in variable attributes

According to GCC's own documentation on variable attributes, the correct syntax for declaring an attribute unused is __attribute__((unused)).

However, in many examples and other code online, I frequently see __attribute__((__unused__)) instead, and they appear to both work.

Is there a reason for either specifying or omitting the __ in either case? Does it make any difference, and is there a preferred version? Are there any situations where using one and not the other might cause problems?

Presumably the same applies to other attribute parameters as well?

like image 352
Riot Avatar asked Nov 26 '14 00:11

Riot


1 Answers

At the top of the very page you linked, it tells you:

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.

Identifiers containing double underscores (__) are reserved to the implementation. Hence no user program could legally define them as macros.

like image 84
T.C. Avatar answered Nov 14 '22 23:11

T.C.