HP 3000 Manuals

Crunched Arrays and Records [ HP Pascal/iX Programmer's Guide ] MPE/iX 5.0 Documentation


HP Pascal/iX Programmer's Guide

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
elements of crunched arrays or fields of crunched records.  If a type is
not in Table 5-5 , a crunched array or record cannot have elements or
fields of that type.

          Table 5-5.  Allocation of Crunched Array Elements 
                      and Record Fields 
                      (HP Pascal Packing Algorithm) 
-------------------------------------------------
|                           |                   |
|   Element or Field Type   |    Allocation     |
|                           |                   |
-------------------------------------------------
|                           |                   |
| Bit16                     | 2 bytes           |
|                           |                   |
-------------------------------------------------
|                           |                   |
| Bit32                     | 4 bytes           |
|                           |                   |
-------------------------------------------------
|                           |                   |
| Bit52                     | 52 bits           |
|                           |                   |
-------------------------------------------------
|                           |                   |
| Boolean                   | 1 bit             |
|                           |                   |
-------------------------------------------------
|                           |                   |
| Char                      | 1 byte            |
|                           |                   |
-------------------------------------------------
|                           |                   |
| Integer1                  | 4 bytes           |
|                           |                   |
-------------------------------------------------
|                           |                   |
| Longint                   | 8 bytes           |
|                           |                   |
-------------------------------------------------
|                           |                   |
| Shortint                  | 2 bytes           |
|                           |                   |
-------------------------------------------------
|                           |                   |
| Crunched array2           | * Minimum #       |
|                           |                   |
-------------------------------------------------
|                           |                   |
| Crunched record2          | * Minimum #       |
|                           |                   |
-------------------------------------------------
|                           |                   |
| Crunched set1             | * Minimum #       |
|                           |                   |
-------------------------------------------------
|                           |                   |
| Subrange1,3               | * Minimum #       |
|                           |                   |
-------------------------------------------------

     (* Minimum number of bits required to represent value.)

   1.  The value representation has the most significant bit first and
       the least significant bit last (no byte swapping).

   2.  If a record or array contains a crunched structure, it must be
       crunched itself.

   3.  The value zero is always included in the subrange when calculating
       the minimum number of bits; for example, this record takes seven
       bits:

            CRUNCHED RECORD
               f : 100..101;
            END;

       If any element can be negative, an extra bit is allocated for the
       sign; for example, this record takes three bits:
       [REV BEG]

            CRUNCHED RECORD
              f : -4..3;
            END;
       [REV END]

Example 

A record that is defined:

     TYPE
        u_rec = RECORD         {4-byte aligned}
           a,b : Boolean;
           c : char;
           d : minint..maxint;
           e : Boolean;
        END;

is allocated and aligned this way:

[]
A record that is defined: TYPE p_rec1 = PACKED RECORD {Byte-aligned} a,b : Boolean; c : char; d : minint..maxint; e : Boolean; END; is allocated and aligned this way:
[]
A record that is defined: p_rec2 = PACKED RECORD {4-byte-aligned} a,b : Boolean; c : char; d : integer; e : Boolean; END; is allocated and aligned this way:
[]
A record that is defined: TYPE c_rec1 = CRUNCHED RECORD a,b : Boolean; c : char; d : minint..maxint; e : Boolean END; Or: TYPE c_rec2 = CRUNCHED RECORD a,b : Boolean; c : char; d : integer; e : Boolean END; is allocated and aligned this way:
[]
The bits containing question marks are not allocated if the type is used inside another crunched structure.


MPE/iX 5.0 Documentation