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

5-: 14
Table 5-4. Allocation and Alignment of Packed Record Fields
(HP Pascal Packing Algorithm) (cont.)
-----------------------------------------------------------------------------------------------
| | | |
| Field Type | Allocation | Field Alignment |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| Record, packed | Fields are allocated by type, and record is padded | Largest alignment |
| | to the alignment boundary. | of any field or |
| | | byte, whichever |
| | | is larger. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| Record, unpacked | Fields are allocated by type, and record is padded | Largest alignment |
| | to the alignment boundary. | of any field. |
| | | |
-----------------------------------------------------------------------------------------------
| | |
| Set | See "Sets" . |
| | |
-----------------------------------------------------------------------------------------------
| | | |
| Shortint | 2 bytes | 2-byte |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| Strings | See "Strings" . | 4-byte |
| | | |
-----------------------------------------------------------------------------------------------
| | |
| Subrange | See "Enumerations and Subranges" . |
| | |
-----------------------------------------------------------------------------------------------
The field that is aligned on the largest boundary determines the
alignment of the entire record. For example, if a record has three
fields--one byte-aligned field, one 2-byte-aligned field, and one
4-byte-aligned field--the entire record is 4-byte-aligned.
Packing a record has no effect on fields that are unpacked structures.
Example
TYPE
ua = ARRAY [1..4] OF Boolean;
ur1 = RECORD
i : integer;
c : char;
END;
VAR
ur2 : RECORD
c : char;
a : ua;
r : ur1;
END;
pr : PACKED RECORD
c : char;
a : ua;
r : ur1;
END;
The fields in ur2 and pr are allocated and aligned identically.
Crunched Arrays and Records
Crunched packing,
a systems programming extension, packs a record or
array as tightly as possible: it bit-aligns every field or element.
Table 5-5 shows how the HP Pascal packing algorithm allocates