Ada Programming/Pragmas/Pack:3

From Wikibooks, open books for an open world
Jump to: navigation, search

Exact data representation[edit]

It is important to realize that pragma Pack must not be used to specify the exact representation of a data type, but to help the compiler to improve the efficiency of the generated code.[1] The compiler is free to ignore the pragma, therefore if a specific representation of a type is required, representation clauses should be used instead (record representation clauses, and/or attributes 'Size or 'Component_Size).

Bit-wise operations[edit]

Although in Ada 83 packed boolean arrays were used for bit-wise operations,[2] since Ada 95 modular types are more adequate for these operations.[3] The argument may be weighed against the advantages of named Boolean array indexes such as Traffic_Lights'(Red => True, others => False), depending on use case.