Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Pascal/HP-UX Programmer's Guide > Chapter 5 Allocation and Alignment

Crunched Arrays and Records

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

Crunched packing, a systems programming extension, packs a record or array as tightly as possible: it bit-aligns every field or element.

Table 5-7 “Allocation of Crunched Array Elements and Record Fields (HP Pascal Packing Algorithm) ” 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-7 “Allocation of Crunched Array Elements and Record Fields (HP Pascal Packing Algorithm) ”, a crunched array or record cannot have elements or fields of that type.

Table 5-7 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:

    CRUNCHED RECORD
    f : -4..3;
    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:

Figure 5-14 Crunched Arrays and Records Example 1

Crunched Arrays and Records Example 1

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:

Figure 5-15 Crunched Arrays and Records Example 2

Crunched Arrays and Records Example 2

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:

Figure 5-16 Crunched Arrays and Records Example 3

Crunched Arrays and Records Example 3

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:

Figure 5-17 Crunched Arrays and Records Example 4

Crunched Arrays and Records Example 4

The bits containing question marks are not allocated if the type is used inside another crunched structure.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.