Go to the previous, next section.
The keyword __attribute__ allows you to specify special
attributes of variables or structure fields. This keyword is followed
by an attribute specification inside double parentheses. Four
attributes are currently defined: aligned, format,
mode and packed. format is used for functions,
and thus not documented here; see section Declaring Attributes of Functions.
aligned (alignment)
int x __attribute__ ((aligned (16))) = 0;
causes the compiler to allocate the global variable x on a
16-byte boundary. On a 68040, this could be used in conjunction with
an asm expression to access the move16 instruction which
requires 16-byte aligned operands.
You can also specify the alignment of structure fields. For example, to
create a double-word aligned int pair, you could write:
struct foo { int x[2] __attribute__ ((aligned (8))); 2;
This is an alternative to creating a union with a double member
that forces the union to be double-word aligned.
It is not possible to specify the alignment of functions; the alignment of functions is determined by the machine's requirements and cannot be changed. You cannot specify alignment for a typedef name because such a name is just an alias, not a distinct type.
The aligned attribute can only increase the alignment; but you
can decrease it by specifying packed as well. See below.
The linker of your operating system imposes a maximum alignment. If the linker aligns each object file on a four byte boundary, then it is beyond the compiler's power to cause anything to be aligned to a larger boundary than that. For example, if the linker happens to put this object file at address 136 (eight more than a multiple of 64), then the compiler cannot guarantee an alignment of more than 8 just by aligning variables in the object file.
mode (mode)
packed
packed attribute specifies that a variable or structure field
should have the smallest possible alignment--one byte for a variable,
and one bit for a field, unless you specify a larger value with the
aligned attribute.
To specify multiple attributes, separate them by commas within the double parentheses: for example, `__attribute__ ((aligned (16), packed))'.
Go to the previous, next section.