mihkhub / gtoolchain-in-action

GNU toolchain in action
0 stars 0 forks source link

Specifying Attributes of Types #6

Open mihkhub opened 6 years ago

mihkhub commented 6 years ago

The keyword __attribute__ allows you to specify special attributes of struct and union types when you define such types.

mihkhub commented 6 years ago

aligned (alignment)

This attribute specifies a minimum alignment (in bytes) for variables of the specified type. For example, the declarations:

struct S { short f[3]; } __attribute__ ((aligned (8)));
typedef int more_aligned_int __attribute__ ((aligned (8)));

force the compiler to ensure (as far as it can) that each variable whose type is struct S or more_aligned_int is allocated and aligned at least on a 8-byte boundary.

mihkhub commented 6 years ago

packed

This attribute, attached to struct or union type definition, specifies that each member (other than zero-width bit-fields) of the structure or union is placed to minimize the memory required. When attached to an enum definition, it indicates that the smallest integral type should be used.