Annotated Ada Reference ManualLegal Information
Contents   Index   References   Search   Previous   Next 

13.2 Pragma Pack

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


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

Legality Rules

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

Static Semantics

{representation pragma (Pack) [partial]} {pragma, representation (Pack) [partial]} {aspect of representation (packing) [partial]} {packing (aspect of representation)} {packed} 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. 
Ramification: The only high level semantic effect of a pragma Pack is independent addressability (see 9.10, “Shared Variables”). 

Implementation Advice

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. 
Implementation Advice: Storage allocated to objects of a packed type should be minimized.
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. 
  {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. 
{recommended level of support (pragma Pack) [partial]} The recommended level of support for pragma Pack is: 
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). 
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. 
Implementation Advice: The recommended level of support for pragma Pack should be followed.

Wording Changes from Ada 95

{AI95-00291-02} Added clarification that pragma Pack 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.

Contents   Index   References   Search   Previous   Next 
Ada-Europe Sponsored by Ada-Europe