HP Pascal/iX Programmer's Guide (31502-90023)
A-: 25
Packed Subranges of Enumerations.
This subsection explains how the Pascal/V packing algorithm allocates and
aligns packed variables whose types are subranges of enumerations. These
packed variables are either the elements of packed arrays or the fields
of packed records. The algorithm treats the two cases differently.
The number of bits that an enumeration of a subrange type requires is
determined by ord(
upper_bound_of_enumerated_subrange
).
Table A-8 shows the relationship between the number of bits that an
enumeration-of-subrange element of a packed array requires, the number of
bits that the Pascal/V packing algorithm allocates it, and its alignment.
No element crosses a 2-byte boundary.
Table A-8. Allocation and Alignment of Enumeration-of-Subrange Elements of Packed Arrays
(Pascal/V Packing Algorithm)
-------------------------------------------------------------------------------------
| | | |
| Required Number of Bits | Number of Bits Allocated | Alignment |
| Per Element | Per Element | |
| | | |
-------------------------------------------------------------------------------------
| | | |
| 1 | 1 | Bit |
| | | |
-------------------------------------------------------------------------------------
| | | |
| 2 | 2 | Bit |
| | | |
-------------------------------------------------------------------------------------
| | | |
| 3 | 3 | Bit |
| | | |
-------------------------------------------------------------------------------------
| | | |
| 4 | 4 | Bit |
| | | |
-------------------------------------------------------------------------------------
| | | |
| 5 | 5 | Bit |
| | | |
-------------------------------------------------------------------------------------
| | | |
| 6 to 8 | 8 (1 byte) | Byte |
| | | |
-------------------------------------------------------------------------------------
| | | |
| 9 to 16 | 16 (2 bytes) | 2-byte |
| | | |
-------------------------------------------------------------------------------------
Example
TYPE
enum_32 = (e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,
e11,e12,e13,e14,e15,e16,e17,e18,e19,e20,
e21,e22,e23,e24,e25,e26,e27,e28,e29,e30,
e31,e32);
VAR
a : PACKED ARRAY [1..4] OF e7..e15;
b : PACKED ARRAY [1..4] OF e24..e31;
Each element of array a requires and is allocated four bits (see Table
A-6 ). The elements are bit-aligned, and the entire array occupies 16
bits. It is allocated two bytes: