DATA TYPES CONVERSION Programmer's Guide: HP 3000 MPE/iX Computer Systems > Chapter 2 Formatting Data TypesFormatting Data in Programs |
|
The correct format for data in a program depends on the programming environment and the programming language. MPE XL has two programming environments: NM and CM. NM is based on a 32-bit word. CM emulates MPE V; both are based on a 16-bit word. In NM, data types are aligned on 32-bit boundaries, by default, to improve performance. Many structures that are aligned on 32-bit boundaries in MPE XL NM are aligned on 16-bit bundaries in MPE V/E. You may have to plan for accurate conversion in mixed-mode applications. Commands and compiler options are provided by supported languages to control alignment. For example, in COBOL you can choose compiler options for 32-bit NM standard or 16-bit CM standard boundaries. Choose CALLALIGNED or CALLALIGNED[16] to specify alignment in calling programs, and choose LINKALLIGNED and LINKALLIGNED[16] to specify program default alignment. In Pascal and FORTRAN, compiler options HP3000_32 and HP3000_16 specify NM or CM standard alignment and real number format. For example, choosing HP3000_16 will cause the compiler to align data in records on 16-bit CM standard boundaries instead of 32-bit NM standard boundaries, and to format floating point real numbers in HP3000 standard notation instead of IEEE NM notation that is standard in NM. For an application to use both NM and CM aligned data files, you could specify the program record definitions to force alignment on a structure-by-structure basis. For example, sync16 or sync32 in COBOL , or $alignment$ in Pascal does this. In this manual, assume that data types are MPE XL Native Mode data types and NM aligned. If CM is meant, CM will be specifically mentioned. Table 2-5 “Correspondence of Data Types Across Languages: Intrinsics, BASIC, and C”, following, shows corresponding data types in the different NM languages: Table 2-5 Correspondence of Data Types Across Languages: Intrinsics, BASIC, and C
Table 2-6 Correspondence of Data Types Across Languages: COBOL, FORTRAN, and Pascal
The following notes relate to the language-specific information in the above table. For further information, consult the manual for the individual languages. Intrinsic parameters may require data of type address (@32 and @64). Address is a 32-bit or 64-bit integer that represents a location in memory. The system recognizes by the context of the command that it is to access or operate on the memory cell at that address.
Booleans (B) are typically one byte long. Only the rightmost bit, bit (7:1), is interpreted. If this bit is odd (usually 1), the logical value is true; if it is even (usually 0), the boolean value is false. (See the notes for Booleans in HP C/XL). Records (intrinsic type REC) and arrays (A) are sets of related data. Each piece of the data is in a field, and the fields are connected. The size and type of the fields are specified when the array or record is created. The fields in a record can vary in size and can contain various types. The fields in an array, called the elements of the array, are all the same size and all contain the same data types. Arrays are often defined in the supported languages with a notation like [lb:ub] or (lb..ub), where lb is the lower bound of the array, and ub is the upper bound. Arrays and records are complex data types that can themselves be used to build more complex data types, such as an array of records. For more information about intrinsic data types, refer to MPE V/E Intrinsics Reference Manual (32033-90007) Compiler library routines are designed to work with the packed decimal, not the BASIC floating-point decimal. The BASIC decimal bit format is explained in the previous section on decimals in this chapter. For more information about HP Business BASIC/XL data types, refer to HP Business BASIC/XL Reference Manual (32715-90001) HP C/XL notates 32-bit addresses with *name and 64-bit addresses with ^name, where name is the type of the data being addressed. In HP C/X a Boolean is stored as any character type; value of zero represents false, and any non-zero is interpreted as true. The C language has certain data conversion conventions for parameter passing. It requires that floats be converted to doubles, that chars be converted to ints, and that arrays of type T be converted to pointers to type T. Formal parameters are actually declared as the "converted" type. For example, if you declare a formal parameter as an array of type T, it is actually declared as a pointer to type T. For more information about HP C/XL data types, refer to HP C Reference Manual (92434-90001) and HP C/XL Reference Manual Supplement (31506-90001) HP COBOL II/XL integers may not be an exact match when exchanged with other languages. They match in size and you can store data across languages, but you may have difficulties in computational operations. The COBOL unsigned integer is different from the Pascal integers. COBOL integers may also have a smaller range. (See the section in the next chapter about converting decimals to integers.) In HP COBOL II/XL, you use clauses to specify three things about data: SIGN, USAGE, and PIC (PICTURE). The optional SIGN clause indicates whether a number will have an operational sign in non-standard position in its representation. You indicate the usage of data in the USAGE clause. Usage is DISPLAY (ASCII alphanumeric type) by default Several COMPUTATIONAL uses can be specified instead. PIC clauses define type, size and symbols to be inserted into elementary expressions. The PIC clause specifies the number of digits; PIC 9(n) indicates a numeric expression n digits long, and PIC S9 indicates a signed number one digit long. A letter V in the PIC clause indicates the position to insert the the decimal point. (Default is decimal rightmost, or integer.) Other symbols are used for placing such insertions as comma separators. For example, to set up a field with three digits to the left of the decimal and two to the right, you would specify PIC 999V99, or PIC 9(3)V9(2). Unpacked Decimals: Unpacked decimals, display type, use ASCII alphanumeric representations for numbers. Represent unsigned digits with the ASCII characters 0 to 9. For signed numbers, use the following ASCII character representations:
The COBOL number line for usage display unpacked signed decimal digits looks like this, then:
For further information, refer to HP COBOL II/XL Programmer's Guide (31500-90002) or COBOL II Reference Manual (31500-90001) and COBOL II/XL Reference Manual Supplement (31500-90005). In HP FORTRAN 77/XL, LOGICAL and INTEGER default to 32 bits. Using the $SHORT compiler option will cause the default to be 16 bits. Using *2 or *4, however, will override any compiler options. For further information, refer to HP FORTRAN 77/XL Programmer's Guide (31501-90002) or HP FORTRAN 77/XL Reference Manual (31501-90010) HP Pascal/XL recognizes 32-bit addresses as LOCALANYPTR or any normal pointer type, and 64-bit addresses as GLOBALANYPTR or any pointer type declared with the $extnaddr$ compiler directive. For further information, refer to HP Pascal Reference Manual (31502-90001), and HP Pascal Programmer's Guide (31502-90002) Language information is in the following manuals:
|