Type Attributes
The type attributes aligned
and packed
are optional in declarations and do not actually affect the type of declared object.
Attribute aligned
This attribute specifies a minimum alignment (in bytes) for variables of the specified type. For example, the declarations:
typedef aligned(32) int aligned32_int;
or alternative syntax :
typedef __attribute__((aligned (32))) int aligned32_int;
This will force the compiler to insure that each variable whose type is aligned32_int
will be allocated and aligned at least on a 32-byte boundary.
The aligned attribute can only increase the alignment, but you can decrease it by specifying packed as well.
Attribute packed
This attribute, attached to struct or union type definition, specifies that each member of the structure or union will be placed in such a way to minimize the memory required.
Specifying this attribute for struct and union types is equivalent to specifying the packed attribute on each of the structure or union members.
struct str1 { char t; int y; long hh; } packed nn;
or alternative syntax :
struct str1 { char t; int y; long hh; } __attribute__((packed)) nn;
You may only specify this attribute on the definition of an struct or union.
What do you think about this topic ? Send us feedback!