HP 3000 Manuals

Packed Arrays [ HP Pascal/iX Programmer's Guide ] MPE/iX 5.0 Documentation


HP Pascal/iX Programmer's Guide

Packed Arrays 

Table 5-3  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-3.  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 | Byte              |
|                   | or record (see Table 5-9 ); then padded to the   |                   |
|                   | nearest byte.                                       |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| Array, packed     | Same as packed array that is not part of an array   | Same as element,  |
|                   | or record (find element type in this table and use  | or byte,          |
|                   | formula in section "Arrays" ); then padded to    | whichever is      |
|                   | alignment boundary.                                 | larger.           |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| Array, unpacked   | Same as unpacked array that is not part of an array | Same as element.  |
|                   | or record (find element type in this table and use  |                   |
|                   | formula in section "Arrays" ).                   |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| 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  | Byte              |
|                   | to byte boundary.                                   |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------

          Table 5-3.  Allocation and Alignment of Packed Array Elements 
                      (HP Pascal Packing Algorithm) (cont.) 
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
|   Element Type    |                     Allocation                      |     Alignment     |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| Record, packed    | Fields are allocated by type, and record is padded  | Largest alignment |
|                   | to the alignment boundary.                          | 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.                          | 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.


MPE/iX 5.0 Documentation