AARM95 - Pragma Pack
Author: JTC1/SC22/WG9/ARG, by Randall Brukardt, ARG Editor

Contents Index Previous Next

# 13.2 Pragma Pack

1
[A pragma Pack specifies that storage minimization should be the main criterion when selecting the representation of a composite type.]

#### Syntax

2
The form of a pragma Pack is as follows:
3
pragma Pack(first_subtype_local_name);

#### Legality Rules

4
The first_subtype_local_name of a pragma Pack shall denote a composite subtype.

#### Static Semantics

5
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.a
Ramification: The only high level semantic effect of a pragma Pack is independent addressability (see 9.10, ``Shared Variables'').

#### 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
Ramification: A pragma Pack 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, a pragma Pack.
7
The recommended level of support for pragma Pack is:
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

- For a packed array type, if the component subtype's Size 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.

Contents Index Previous Next Legal