HP 3000 Manuals

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


HP Pascal/iX Programmer's Guide

Records 

A record allocation is the sum of the allocations of the fields in the
fixed part and (if the record has them) the allocations of the tag field
and the largest field in the variant part, plus trailing bits.

Field allocation depends on field type and whether the record is
unpacked, packed, or crunched.  The same factors determine field
alignment.  See the tables indicated below:

If the array is:      See:                  In the section: 

Unpacked              Table 5-1          "Unpacked Variables"

Packed                Table 5-4          "Packed Records"  

Crunched              Table 5-5          "Crunched Arrays and
                                            Records"  

The HP Pascal packing algorithm uses these two rules to align a record:

   *   The entire record is aligned on the same boundary as its most
       restricted field.

   *   The variant part of a record is aligned on the same boundary as
       the most restricted first field of all variants.

Example 

     TYPE
        Rec = RECORD
                 CASE b : Boolean OF
                    TRUE  : (c : char;      {1 byte,  1-byte-aligned}
                             l : longreal;  {8 bytes, 8-byte-aligned}
                            );
                    FALSE : (i : integer;   {4 bytes, 4-byte-aligned}
                            );
              END;

A record of the type Rec is 8-byte-aligned because its most restricted
field, l, must be 8-byte-aligned.

The variant part of a record of type Rec is 4-byte-aligned, because
the most restricted first field of the two variants, i, must be
4-byte-aligned.

A variable of type Rec is allocated 16 bytes.  The TRUE and FALSE
variants are aligned like this:

TRUE Variant 

[]
FALSE Variant
[]
Sometimes you can reduce the space that a record takes by declaring its fields in different order. Example VAR upr1 : RECORD bf : Boolean; pf : 0..32767; cf : char; END; upr2 : RECORD bf : Boolean; cf : char; pf : 0..32767; END; The only difference between the variables upr1 and upr2 is the order of their fields. The variable upr1 takes six bytes:
[]
Because pf must be 2-byte-aligned, it cannot start in the second byte. The extra byte after cf is allocated because the most restricted element, pf, is 2-byte-aligned. The variable upr2 takes four bytes:
[]
Sometimes you cannot reduce the space that a record takes by declaring its fields in different order. Example VAR pr1 : PACKED RECORD srf : 0..32; b : Boolean; pf : 0..32767; cf : char; END; pr2 : PACKED RECORD srf : 0..32; b : Boolean; cf : char; pf : 0..32767; END; The only difference between the variables pr1 and pr2 is the order of their fields. The variable pr1 takes four bytes:
[]
The variable pr2 also takes four bytes:
[]


MPE/iX 5.0 Documentation