Next: Size Clauses, Up: Representation Clauses and Pragmas
GNAT requires that all alignment clauses specify a power of 2, and all default alignments are always a power of 2. The default alignment values are as follows:
Storage_Unit
,
and the maximum alignment supported by the target.
(This maximum alignment is given by the GNAT-specific attribute
Standard'Maximum_Alignment
; see Maximum_Alignment.)
For example, for type Long_Float
, the object size is 8 bytes, and the
default alignment will be 8 on any target that supports alignments
this large, but on some targets, the maximum alignment may be smaller
than 8, in which case objects of type Long_Float
will be maximally
aligned.
Pack
is
used and all fields are packable (see separate section on pragma Pack
),
then the resulting alignment is 1.
A special case is when:
type Small is record A, B : Character; end record; for Small'Size use 16;
then the default alignment of the record type Small
is 2, not 1. This
leads to more efficient code when the record is treated as a unit, and also
allows the type to specified as Atomic
on architectures requiring
strict alignment.
An alignment clause may specify a larger alignment than the default value
up to some maximum value dependent on the target (obtainable by using the
attribute reference Standard'Maximum_Alignment
). It may also specify
a smaller alignment than the default value, for example
type V is record A : Integer; end record; for V'alignment use 1;
The default alignment for the type V
is 4, as a result of the
Integer field in the record, but it is permissible, as shown, to
override the default alignment of the record with a smaller value.