| United States-English |
|
|
|
![]() |
HP Pascal/HP-UX Programmer's Guide > Chapter 5 Allocation and Alignment Enumerations and Subranges |
|
HP Pascal allocates and aligns variables of enumeration and subrange types the same way. An enumeration of n elements and the subrange 0..n-1 are equivalent. The allocation and alignment are based on the values of the subrange or the ordinal value of the enumeration. Example
The compiler allocates and aligns the variables enum_var and subr_var the same way. The allocation and alignment of an enumeration or subrange variable depends on whether it is:
Table 5-9 “Allocation and Alignment of Unpacked Enumeration or Unsigned Subrange Variables (HP Pascal Packing Algorithm) ” shows how the HP Pascal packing algorithm allocates and aligns unpacked enumeration or unsigned subrange variables. Table 5-9 Allocation and Alignment of Unpacked Enumeration or Unsigned Subrange Variables (HP Pascal Packing Algorithm)
An unpacked, signed subrange is always allocated four bytes. Example The value zero is always included in the subrange when the minimum number of bits is calculated.
A packed enumeration or subrange variable requires the minimum number of bits needed to represent its values in a record. It is bit-aligned. If the enumeration or subrange variable belongs to a packed array, the HP Pascal packing algorithm allocates it the smallest power of two bits that is greater than or equal to the number of bits it requires, and aligns it on that boundary. Table 5-10 “Allocation and Alignment of Packed Array Elements of Enumeration or Subrange Type (HP Pascal Packing Algorithm)” shows the relationship between the number of bits that a packed array element of an enumeration- or subrange-type array requires, the number of bits that the HP Pascal packing algorithm allocates to it, and its alignment. Table 5-10 Allocation and Alignment of Packed Array Elements of Enumeration or Subrange Type (HP Pascal Packing Algorithm)
Example
Each element of the array pa1 requires two bits. Two is a power of two, so each element is allocated two bits. The entire array occupies 10 bits. It is allocated two bytes: Each element of the array pa2 requires three bits. The smallest power of two that is greater than or equal to three is four, so each element is allocated four bits. The entire array occupies 20 bits. It is allocated three bytes: If the variable belongs to a packed record, the HP Pascal packing algorithm allocates it as many bits as it requires, and bit-aligns it. Example
Each field of the record r requires three bits. The entire record occupies 33 bits. It is allocated five bytes:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||