HP Pascal/iX Programmer's Guide (31502-90023)

A-: 15
| | |
-----------------------------------------------------------------------------------------------
| | |
| Subrange of enumeration | See "Packed Subranges of Enumerations" |
| | |
-----------------------------------------------------------------------------------------------
| | |
| Subrange of integer | See "Packed Subranges of Integers" |
| | |
-----------------------------------------------------------------------------------------------
Arrays.
This section applies to the allocation of unpacked and packed arrays.
For alignment, see Table A-2 and Table A-3 .
The Pascal/V packing algorithm stores arrays in row-major order (for a
definition of row-major order, see Chapter 5 ).
The Pascal/V packing algorithm uses this formula to allocate an array:
(
number_of_elements
*
space_for_one_element
)
+
number_of_internal_unused_bits
+
number_of_trailing_pad bits
The
space_for_one_element
depends on the element type and whether the
array is unpacked or packed. If the array is unpacked, find its type in
Table A-2 . If the array is packed, find its type in Table A-3 .
If
space_for_one_element
is less than 16 bits, the
number_of_internal_unused_bits
is
16-((16 DIV space_for_one_element) * space_for_one_element)
otherwise, it is zero.
The
number_of_trailing_pad_bits
is the number of leftover bits in the
last byte or word (whichever each element is allocated).
Example
TYPE
day = (sun,mon,tues,wed,thurs,fri,sat);
VAR
ua : ARRAY [1..8] OF day;
pa : PACKED ARRAY [1..8] OF day;
Each element of ua takes one byte. The entire array takes eight bytes,
with no internal unused bits and no trailing pad bits. The array ua is
allocated and aligned like this:
Each element of pa takes three bits. No element can cross a 2-byte
boundary, so the bit following pa[5] is unused. The entire array takes
four bytes, with one internal unused bit and seven trailing pad bits. It