Ada Programming/Pragmas/Pack

pragma Pack (local_name);

Description
Pack is a representation pragma that directs the compiler to use type representations that favor conservation of storage space, rather than ease of access. It can be used with composite types, like arrays and records. Using pragma Pack will usually result in smaller data structures at the cost of additional operations to retrieve each element (bit operations may be required in order to retrieve packed data). This may or may not result in a loss of execution time, since the increase of instructions executed to access each element can be cheaper than the cost to read an unpacked data structure from memory.

Example
Packed_Bool_Array  (1 .. 8)  Boolean; (Packed_Bool_Array);

Portability
The pragma Pack is standard in the language since Ada 83. However, implementations are allowed to produce different results or to ignore it completely, and therefore it is not portable between compilers. It can produce different results depending on the target architecture too. Thus the pragma Pack should not be used when an exact representation is required for a type.

Interfacing
There is no equivalent standard feature in other programming languages as far as the authors know, so this pragma should not be used when interfacing.

GCC provides an extension to the C programming language that can be used to pack structs, unions (equivalent to Ada's records) or enumeration types. Note that the packed attribute is not a standard feature of the C language, and cannot be used with arrays like in Ada.

Wikibook

 * Ada Programming
 * Ada Programming/Pragmas
 * Ada Programming/Pragmas/Optimize
 * Ada Programming/Pragmas/Implicit_Packing (implementation defined)
 * Ada Programming/Attributes/'Size
 * Ada Programming/Attributes/'Component_Size
 * Ada Programming/Types/mod