__attribute__ is a keyword introduced by GCC. It is regarded as an extension of a language. It helps the compiler optimize calls, check code more carefully for correctness, control memory placement and code generation options.

Syntax

1
__attribute__ ((attribute-list))

where an attribute-list is a possibly empty comma-separated sequence of attributes. Say:

1
static void _init( void ) __attribute__((constructor));

Categories

Let’s say to specify an attribute of variables.

1
2
extern __thread struct _glapi_table * _glapi_tls_Dispatch
__attribute__((tls_model("initial-exec")));

where the tls_model attribute sets thread-local storage model of a particular thread variable, overriding -ftls-model= command-line switch on a per-variable basis. The tls_model argument should be one of global-dynamic, local-dynamic, initial-exec, or local-exec.

Visibility

1
__attribute__((visibility("default")));

this attribute involves with the visibility of exported symbols in a shared object, overriding -fvisibility=hidden command-line option during the compilation. The visibility argument should be one of default, hidden, internal, or protected.