13.2 Packed TypesPragma Pack
1/3
{
AI05-0229-1}
[
The Pack aspect having the value True A
pragma Pack
specifies that storage minimization should be the main criterion when
selecting the representation of a composite type.]
Syntax
2/3
3/3
Legality Rules
4/3
Static Semantics
5/3
{
AI05-0229-1}
For a full type declaration
of a composite type, the following language-defined representation aspect
may be specified: A
pragma Pack
specifies the packing aspect of representation; the type (or the
extension part) is said to be packed. For a type extension, the
parent part is packed as for the parent type, and a pragma
Pack causes packing only of the extension part.
5.1/3
Pack
The type of aspect Pack is Boolean. When aspect
Pack is True for a type, the type (or the extension part) is said to
be packed. For a type extension, the parent part is packed as
for the parent type, and specifying Pack causes packing only of the extension
part.
5.a/3
Aspect Description
for Pack: Minimize
storage when laying out records and arrays.
5.2/3
If directly specified,
the aspect_definition
shall be a static expression. If not specified (including by inheritance),
the aspect is False.
5.b/3
Implementation Advice
6
If a type is packed, then the implementation should
try to minimize storage allocated to objects of the type, possibly at
the expense of speed of accessing components, subject to reasonable complexity
in addressing calculations.
6.a.1/2
Implementation Advice:
Storage allocated to objects of a packed
type should be minimized.
6.a/3
Ramification: {
AI05-0229-1}
Specifying the A pragma
Pack
aspect is for gaining space efficiency,
possibly at the expense of time. If more explicit control over representation
is desired, then a
record_representation_clause,
a Component_Size clause, or a Size clause should be used instead of,
or in addition to,
the a
pragma
Pack
aspect.
6.1/2
{
AI95-00291-02}
If a packed type has a component that is not of
a by-reference type and has no aliased part, then such a component need
not be aligned according to the Alignment of its subtype; in particular
it need not be allocated on a storage element boundary.
7/3
8
For a packed record type, the components should
be packed as tightly as possible subject to the Sizes of the component
subtypes, and subject to any
record_representation_clause
that applies to the type; the implementation may, but need not, reorder
components or cross aligned word boundaries to improve the packing. A
component whose Size is greater than the word size may be allocated an
integral number of words.
8.a
Ramification: The implementation can
always allocate an integral number of words for a component that will
not fit in a word. The rule also allows small component sizes to be rounded
up if such rounding does not waste space. For example, if Storage_Unit
= 8, then a component of size 8 is probably more efficient than a component
of size 7 plus a 1-bit gap (assuming the gap is needed anyway).
9/3
{
AI05-0009-1}
For a packed array type, if the
component subtype's
Size
of the component subtype is
less than or equal to the word size
, and Component_Size
is not specified for the type, Component_Size should be less than
or equal to the Size of the component subtype, rounded up to the nearest
factor of the word size.
9.a
Ramification: If a component subtype
is aliased, its Size will generally be a multiple of Storage_Unit, so
it probably won't get packed very tightly.
9.b/3
Implementation Advice: The
recommended level of support for the pragma Pack aspect should be followed.
Wording Changes from Ada 95
9.c/3
{
AI95-00291-02}
{
AI05-0229-1}
Added clarification that the pragma Pack aspect can ignore alignment requirements on types that don't have by-reference
or aliased parts. This was always intended, but there was no wording
to that effect.
Extensions to Ada 2005
9.d/3
Wording Changes from Ada 2005
9.e/3
{
AI05-0009-1}
Correction: Fixed so that the presence or
absence of a confirming Component_Size representation clause does not
change the meaning of the Pack aspect.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe