HP Pascal/iX Programmer's Guide (31502-90023)

5-: 19
Table 5-7. Allocation and Alignment of Unpacked Enumeration or Unsigned Subrange
Variables (HP Pascal Packing Algorithm)
---------------------------------------------------------------------------------------
||||
|Values in Enumeration or Subrange |||
||Allocation | Alignment |
||||
---------------------------------------------------------------------------------------
||||
| 0..255 | 1 byte | byte |
||||
---------------------------------------------------------------------------------------
||||
| 256..65535 | 2 bytes | 2-byte |
||||
---------------------------------------------------------------------------------------
||||
| 65536..maxint | 4 bytes | 4-byte |
||||
---------------------------------------------------------------------------------------
An unpacked, signed subrange is always allocated four bytes.
Example
The value zero is always included in the subrange when the minimum number
of bits is calculated.
TYPE
enum_type = (red,blue,yellow); {3 elements}
subr_type1 = 1..300; {Including zero, 2 bytes}
subr_type2 = 1..66000; {Including zero, 4 bytes}
subr_type3 = 100000..100010; {Including zero, 4 bytes}
subr_type4 = -1..200; {4 bytes}
VAR
enum_var : enum_type; {Allocated 1 byte, byte-aligned}
subr_var1 : subr_type1; {Allocated 2 bytes, 2-byte-aligned}
subr_var2 : subr_type2; {Allocated 4 bytes, 4-byte-aligned}
subr_var4 : subr_type4; {Allocated 4 bytes, 4-byte-aligned}
unpacked_array : ARRAY [1..3] OF enum_type; {Each element is
allocated one byte
and is byte-aligned}
unpacked_record : RECORD
f1 : subr_type1; {Allocated 2 bytes,
2-byte-aligned}
f2 : subr_type2; {Allocated 4 bytes,
4-byte-aligned}
END;
Packed Array Elements of Enumeration or Subrange Types
A packed enumeration or subrange variable
requires
the minimum number of
bits needed to represent its values in a record. It is bit-aligned.
If the enumeration or subrange variable belongs to a packed array, the HP
Pascal packing algorithm allocates it the smallest power of two bits that
is greater than or equal to the number of bits it requires, and aligns it
on that boundary.
Table 5-8 shows the relationship between the number of bits that a
packed array element of an enumeration- or subrange-type array requires,
the number of bits that the HP Pascal packing algorithm allocates to it,
and its alignment.