| United States-English |
|
|
|
![]() |
HP Pascal/HP-UX Programmer's Guide > Appendix A MPE/iX Dependencies MPE/iX Extensions |
|
MPE/iX extensions are available only to programs that are run on the MPE/iX operating system or contain the compiler option OS 'MPE/XL'. They are:
The predefined function ccode returns an integer in the range 0..2, which represents the condition code set by the most recently executed intrinsic or external SPL routine. The correspondence between possible return values and condition codes is:
For the meanings of the condition codes, refer to the MPE/iX Intrinsics Reference Manual. The value that ccode returns is valid between the time that the intrinsic or external SPL routine returns and any subsequent calls that can change the value of ccode, which are:
Example
The predefined function fnum returns the MPE/iX file number of the physical file currently associated with a given logical file. You can use this file number in calls to MPE/iX file system intrinsics. Syntax
Example
The predefined function get_alignment returns the alignment requirement of a given type or variable. For a type, get_alignment returns the minimum possible alignment. For a variable, it returns the actual alignment. Syntax [get_alignment ( {variabletype})] Parameters
Example
The predefined function statement_number returns the statement number of the statement that calls it, as shown on the compiled listing. It is a useful debugging aid, especially when used with the predefined procedure assert. Syntax [statement_number] Example
The predefined procedure setconvert converts a set from HP Pascal packing algorithm (HP3000_32) format to Pascal/V packing algorithm (HP3000_16) format, or vice versa. It is enabled by the HP3000_16 compiler option. Syntax
Parameters Title not available (Setconvert Procedure )
The sets set1 and set2 can vary only in packing algorithm format. Their packing (unpacked, packed, or crunched) and base types must be the same. Their packing algorithm formats cannot be the same. Example
The predefined procedure strconvert converts a string from Pascal/V packing algorithm (HP3000_16) format to HP Pascal packing algorithm (HP3000_32) format. It is enabled by the HP3000_16 compiler option. Syntax
Parameters
Example
The Pascal/V packing algorithm is an alternative to the default HP Pascal packing algorithm that Chapter 5 explains. If you want the compiler to use the Pascal/V packing algorithm, include the compiler option HP3000_16 in your program (see the HP Pascal/iX Reference Manual for more information on the compiler option HP3000_16). HP3000_16 causes the compiler to use the Pascal/V packing algorithm, with these exceptions:
An unpacked variable is either not part of an array or record, or it is part of an unpacked array or record. In either case, it is allocated and aligned the same way. Table A-2 “Allocation and Alignment of Unpacked Variables (Pascal/V Packing Algorithm) ” shows how the Pascal/V packing algorithm allocates and aligns the elements of an unpacked array or the fields of an unpacked record. The element or field types are in alphabetical order. Subsections that Table A-2 “Allocation and Alignment of Unpacked Variables (Pascal/V Packing Algorithm) ” references are in this section, “Pascal/V Packing Algorithm ”. Table A-2 Allocation and Alignment of Unpacked Variables (Pascal/V Packing Algorithm)
A packed variable is the element of a packed array or the field of a packed record. Packed elements and packed fields are allocated and aligned differently. Table A-3 “Allocation and Alignment of Packed Array Elements (Pascal/V Packing Algorithm) ” shows how the Pascal/V packing algorithm allocates and aligns the elements of a packed array. The element types are in alphabetical order. Subsections that Table A-3 “Allocation and Alignment of Packed Array Elements (Pascal/V Packing Algorithm) ” references are in this section, “Pascal/V Packing Algorithm ”. Table A-3 Allocation and Alignment of Packed Array Elements (Pascal/V Packing Algorithm)
Table A-4 “Allocation and Alignment of Packed Record Fields (Pascal/V Packing Algorithm) ” shows how the Pascal/V packing algorithm allocates and aligns the fields of a packed record. The field types are in alphabetical order. Subsections that Table A-4 references are in this section, “Pascal/V Packing Algorithm ”. Table A-4 Allocation and Alignment of Packed Record Fields (Pascal/V Packing Algorithm)
This section applies to the allocation of unpacked and packed arrays. For alignment, see Table A-2 “Allocation and Alignment of Unpacked Variables (Pascal/V Packing Algorithm) ” and Table A-3 “Allocation and Alignment of Packed Array Elements (Pascal/V Packing Algorithm) ”. The Pascal/V packing algorithm stores arrays in row-major order (for a definition of row-major order, see Chapter 5 “Allocation and Alignment ”). The Pascal/V packing algorithm uses this formula to allocate an array:
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 “Allocation and Alignment of Unpacked Variables (Pascal/V Packing Algorithm) ”. If the array is packed, find its type in Table A-3 “Allocation and Alignment of Packed Array Elements (Pascal/V Packing Algorithm) ”. If space_for_one_element is less than 16 bits, the number_of_internal_unused_bits is
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
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 is allocated and aligned like this: The HP Pascal compiler allocates space for an HP3000_16 file this way:
This section applies to unpacked and packed records unless otherwise noted. The Pascal/V packing algorithm does not always align variant parts of fields on the same boundary. Each variant part's boundary depends on its type. Example
A variable of type Rec is allocated 10 bytes. The TRUE and FALSE variants are aligned like this: TRUE Variant FALSE Variant The variants f1 and f2 do not start on the same boundary; therefore, f1 cannot be overlaid with f2. Sometimes you can reduce the space that a record takes by declaring its fields in different order. Example
The only difference between the variables upr1 and upr2 above is the order of their fields. The variable upr1 takes six bytes: Because p must be 2-byte-aligned, it cannot start in the second byte. The sixth byte is allocated to upr1 also, because records are 2-byte-aligned. The variable upr2 takes four bytes: The Pascal/V packing algorithm allocates sets in byte pairs. The number of byte pairs allocated to a set depends on its type. For the types Boolean, char, enumeration, and integer, the formula for the number of byte pairs is:
(where ceil(x) means the integer closest to x that is greater than or equal to x). Table A-5 “Bit and Byte Pair Requirements for Boolean, Char, and Integer Base Types (Pascal/V Packing Algorithm) ” gives the values for bits_required_for_set and number_of_byte_pairs for Boolean, char, and integer types. Table A-5 Bit and Byte Pair Requirements for Boolean, Char, and Integer Base Types (Pascal/V Packing Algorithm)
Same as bit16, bit32, bit52, shortint, and longint. * Integers outside the range 0..255 cannot belong to the set. For enumerated sets, bits_required_for_set is the number of elements in the set, and you must use the formula to determine number_of_byte_pairs. Example
The set days has seven elements and requires seven bits. It is allocated one byte pair (ceil(7/16) = 1). Each element is represented by one bit, like this: The set months has 12 elements and requires 12 bits. It is allocated one byte pair (ceil(12/16) = 1). Each element is represented by one bit. The set set_33 has 33 elements and requires 33 bits. It is allocated three byte pairs (ceil(33/16) = 3). Each element is represented by one bit. For integer subrange sets, the formula for the number of byte pairs is:
The upper bound of the integer subrange determines upper_bound_byte_pair_number, and the lower bound determines lower_bound_byte_pair_number. The formula is: [byte_pair_number = floor(bound / 16)] (where floor(x) means the integer closest to x that is less than or equal to x). Example
The upper bound of the subrange is 18, so upper_bound_byte_pair_number is 1 (floor(18/16)=1). The lower bound of the subrange is -7, so lower_bound_byte_pair_number is -1 (floor(-7/16)=-1). The set s is allocated three byte pairs ((1-(-1))+1=3). Each set element is represented by one bit, like this: To minimize storage space, avoid base types that are small subranges that overlap byte pair boundaries. Example
The set s takes two byte pairs, using 32 bits to represent a set that requires only two bits. The arithmetic is:
The Pascal/V packing algorithm aligns strings on 2-byte boundaries. Because the current length (0..32767) is allocated two bytes, four bytes is the smallest possible string allocation. The formula for the number of bytes allocated to a string is: Example
The string s1 takes 14 bytes:
The allocation is: The string s2 takes 10 bytes:
The allocation is: This subsection explains how the Pascal/V packing algorithm allocates and aligns packed enumeration variables. A packed enumeration variable is either the element of a packed array or the field of a packed record. The algorithm treats the two cases differently. Table A-6 “Allocation and Alignment of Enumeration Elements of Packed Arrays (Pascal/V Packing Algorithm) ” shows the relationship between the number of bits that an enumeration element of a packed array requires, the number of bits that the Pascal/V packing algorithm allocates it, and its alignment. A bit-aligned element never crosses a 2-byte boundary. Table A-6 Allocation and Alignment of Enumeration Elements of Packed Arrays (Pascal/V Packing Algorithm)
Table A-7 “Allocation and Alignment of Enumeration Fields of Packed Records (Pascal/V Packing Algorithm) ” shows the relationship between the number of bits that an enumeration field of a packed record requires, the number of bits that the Pascal/V mapping algorithm allocates it, and its alignment. A bit-aligned field never crosses a 2-byte boundary. Table A-7 Allocation and Alignment of Enumeration Fields of Packed Records (Pascal/V Packing Algorithm)
Example
Each element of the array a requires three bits, and no element can cross a 2-byte boundary. The entire array occupies 35 bits, and is allocated six bytes. Each element of the record r requires three bits, and no element can cross a 2-byte boundary. The entire record occupies 35 bits, and is allocated six bytes. Each element of the array aa requires six bits, but is allocated eight bits (one byte) and is byte-aligned. The entire array takes four bytes: Each field of the record rr requires and is allocated six bits, and no field can cross a 2-byte boundary. The entire record occupies 26 bits, and is allocated four bytes: This subsection explains how the Pascal/V packing algorithm allocates and aligns packed variables whose types are subranges of enumerations. These packed variables are either the elements of packed arrays or the fields of packed records. The algorithm treats the two cases differently. The number of bits that an enumeration of a subrange type requires is determined by ord(upper_bound_of_enumerated_subrange). Table A-8 “Allocation and Alignment of Enumeration-of-Subrange Elements of Packed Arrays (Pascal/V Packing Algorithm) ” shows the relationship between the number of bits that an enumeration-of-subrange element of a packed array requires, the number of bits that the Pascal/V packing algorithm allocates it, and its alignment. No element crosses a 2-byte boundary. Table A-8 Allocation and Alignment of Enumeration-of-Subrange Elements of Packed Arrays (Pascal/V Packing Algorithm)
Example
Each element of array a requires and is allocated four bits (see Table A-6 “Allocation and Alignment of Enumeration Elements of Packed Arrays (Pascal/V Packing Algorithm) ”). The elements are bit-aligned, and the entire array occupies 16 bits. It is allocated two bytes: Each element of array b requires and is allocated five bits (see Table A-6 “Allocation and Alignment of Enumeration Elements of Packed Arrays (Pascal/V Packing Algorithm) ”). The elements are bit-aligned, and the entire array occupies 21 bits. It is allocated four bytes. To the enumeration-of-subrange field of a packed record, the Pascal/V packing algorithm allocates the required number of bits. Any allocation from one bit to two bytes is possible. The field is bit-aligned, but never crosses a 2-byte boundary. Example
Each field of record a requires and is allocated four bits. The fields are bit-aligned, but cannot cross 2-byte boundaries. The entire record is allocated two bytes: Each field of record b requires and is allocated five bits. The fields are bit-aligned, but cannot cross 2-byte boundaries. The entire record occupies 21 bits. It is allocated four bytes: This subsection explains how the Pascal/V packing algorithm allocates and aligns packed variables whose types are subranges of integers. These packed variables are either the elements of packed arrays or the fields of packed records. To the integer subrange variable of a packed array or packed record, the Pascal/V packing algorithm allocates the required number of bits (if the subrange is, or is included in, -32768..32767) or four bytes (if the subrange is outside that range). Table A-9 “Allocation and Alignment of Elements of Packed Arrays of Subrange Type (Pascal/V Packing Algorithm) ” shows the relationship between the number of bits that an element of a PACKED array of subrange type requires, the number of bits that the Pascal/V mapping algorithm allocates it, and its alignment. Table A-9 Allocation and Alignment of Elements of Packed Arrays of Subrange Type (Pascal/V Packing Algorithm)
* Only if the subrange is, or is included in, -32768..32767; four bytes otherwise. Example
Each element of the array a requires and is allocated five bits, and is bit-aligned (see Table A-8 “Allocation and Alignment of Enumeration-of-Subrange Elements of Packed Arrays (Pascal/V Packing Algorithm) ”). The entire array occupies 20 bits. It is allocated four bytes: Each element of the array b requires six bits, is allocated one byte, and is byte-aligned (see Table A-8 “Allocation and Alignment of Enumeration-of-Subrange Elements of Packed Arrays (Pascal/V Packing Algorithm) ”). The entire array occupies four bytes. For the integer subrange type of a packed record, any bit allocation from one bit to 15 bits is possible, as are allocations of two and four bytes. Bit allocations are bit-aligned, but never cross 2-byte boundaries. Two- and 4-byte allocations are 2-byte aligned. See "Records" for more information. Example
The fields of the record r are allocated the bits that they require. Fields a, b, c, and d are bit-aligned, but cannot cross 2-byte boundaries (notice where d and e start). Fields e and f are 2-byte-aligned. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||