Table 5-5 “Allocation and Alignment of Packed Array
Elements (HP Pascal Packing Algorithm) ” shows how the HP
Pascal packing algorithm allocates and aligns the elements of a
packed array. The element types are in alphabetical order.
Table 5-5 Allocation and Alignment of Packed Array
Elements (HP Pascal Packing Algorithm)
Element Type | Allocation | Alignment |
|---|
Anyptr | 8 bytes | 4-bytes |
Array, crunched | Same as crunched array that is not part
of an array or record (see Table 5-11 “Allocation of File Components (HP Pascal
Packing Algorithm) ”);
then padded to the nearest byte. | Byte |
Array, packed | Same as packed array that is not part
of an array or record (find element type in this table and use formula
in section “Arrays ”); then padded
to alignment boundary. | Same as element, or byte, whichever is
larger. |
Array, unpacked | Same as unpacked array that is not part
of an array or record (find element type in this table and use formula
in section “Arrays ”). | Same as element. |
Bit16 | 2 bytes | 2-byte |
Bit32 | 4 bytes | 4-byte |
Bit52 | 8 bytes | 4-byte |
Boolean | 1 bit | 1 bit |
Char | 1 byte | 1-byte |
Enumeration | See “Enumerations and Subranges ”. | |
File | See "Files". | 8-byte |
Function | 8 bytes | 4-byte |
Integer | 4 bytes | 4-byte |
Globalanyptr | 8 bytes | 4-byte |
Localanyptr | 4 bytes | 4-byte |
Longint | 8 bytes | 4-byte |
Longreal | 8 bytes | 8-byte |
Pointer | 4 bytes | 4-byte |
Procedure | 8 bytes | 4-byte |
Real | 4 bytes | 4-byte |
Record, crunched | Fields are allocated by type, and record
is padded to byte boundary. | Byte |
Record, packed | Fields are allocated by type, and record
is padded to the alignment boundary. | Largest alignment boundary of any field,
or byte, whichever is larger. |
Record, unpacked | Fields are allocated by type, and record
is padded to the alignment boundary. | Largest alignment boundary of any field. |
Set | See “Sets ”. |
Shortint | 2 bytes | 2-byte |
Strings | See “Strings ”. | 4-byte |
Subrange | See “Enumerations and Subranges ”. |
Example
VAR uba : ARRAY [1..3] OF Boolean; pba : PACKED ARRAY [1..3] OF Boolean; |
The array uba
takes three bytes:
The array pba
takes three bits:
If an array is not within a crunched structure, the compiler
aligns the entire array on the same boundary as its first element,
or on a byte boundary.
Declaring an array PACKED has no effect on its elements if
the elements are unpacked structures.