__attribute__ in GNU C

declaration, function, gcc

Solution

For what GCC and GCC-compatible compilers use `__attribute__` most other compilers use `#pragma` directives.

I think GCC's solution is better since the required behavior of an unrecognised `#pragma` is to ignore it, whereas if you use a compiler that does not understand an `__attribute__` specification, it will not compile - which is generally better, since you then know what you need to port.

Attribute specifications are used to specify aspects of types, data, and functions such as storage and alignment that cannot be specified using C. Often these are target specific, mostly they are non-portable, certainly between compilers, and often between targets. Avoid their use except where it is absolutely necessary to the correct function of code.

Problem

Why and how is `__attribute__` used in GNU C programs?

Original source