HPlogo DATA TYPES CONVERSION Programmer's Guide: HP 3000 MPE/iX Computer Systems > Chapter 2 Formatting Data Types

Formatting Data in Programs

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

The correct format for data in a program depends on the programming environment and the programming language.

NM and CM Programming Environments

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.

Programming Languages

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

Data TypeIntrinsicsHP Business BASIC/XLHP C/XL
CharacterC$ dimension as 1 characterCHAR or UNSIGNED CHAR
Integer: 16-bit unsignedU16N/AUNSIGNED SHORT INT
Integer: 32-bit unsignedU32N/AUNSIGNED INT or UNSIGNED LONG INT
Integer: 64-bit unsignedU64N/AN/A
Integer: 16-bit signedI16SHORTINT or subrange [-32768..32767]SHORT INT
Integer: 32-bit signedI32INTEGERINT or ENUM
Integer: 64-bit signedI64N/AN/A
Real 32-bit (Single- Precision)R32SHORTREALFLOAT
Real 64-bit (Double- Precision)R64REALDOUBLE
Decimal: PackedN/AN/AN/A
Decimal: UnpackedN/AN/AN/A
Decimal: Floating- PointN/ADecimal or Short DecimalN/A

 

Table 2-6 Correspondence of Data Types Across Languages: COBOL, FORTRAN, and Pascal

Data TypeHP COBOL II/XLHP FORTRAN 77/XLHP Pascal/XL
CharacterDISPLAY or group itemCHARACTERCHARACTER
Integer: 16-bit unsignedPIC S9 to PIC S9(4) COMPLOGICAL OR LOGICAL*20..65535 or any 16-bit SUBRANGE
Integer: 32-bit unsignedPIC S9(5) to PIC S9(9) COMPLOGICAL OR LOGICAL*4Any 32-bit subrange
Integer: 64-bit unsignedPIC S9(10) to PIC S9(18) COMPN/AN/A
Integer: 16-bit signedPIC S9 to PIC S9(4) COMPINTEGER or INTEGER *2SHORTINT or any 16-bit subrange
Integer: 32-bit signedPIC S9(5) to PIC S9(9) COMPINTEGER or INTEGER *4INTEGER or any 32-bit subrange
Integer: 64-bit signedPIC S9(10) to PIC S9(18) COMPN/AN/A
Real 32-bit (Single- Precision)N/AREAL or REAL*4REAL
Real 64-bit (Double- Precision)N/ADOUBLE PRECISION or REAL*8LONGREAL
Decimal: PackedCOMP-3N/AN/A
Decimal: UnpackedDISPLAYN/AN/A
Decimal: Floating-PointN/AN/AN/A

 

Language Notes

The following notes relate to the language-specific information in the above table. For further information, consult the manual for the individual languages.

Intrinsics

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.

NOTE: In this manual, bit fields are described as (bit:length), where bit is the first bit in the field and length is the number of consecutive bits in the field. For example, "bits (11:3)" refers to bits 11, 12, and 13. Bit 0 is the most significant bit.

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)

HP Business BASIC/XL

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

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

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:

  • { represents +0

  • Letters A through I represent digits +1 through +9

  • } represents -0

  • Letters J through R represent digits -1 through -9

The COBOL number line for usage display unpacked signed decimal digits looks like this, then:

  R  Q  P  O  N  M  L  K  J } { A  B  C  D  E  F  G  H  I

 -+--+--+--+--+--+--+--+--+--|--+--+--+--+--+--+--+--+--+-   

 -9 -8 -7 -6 -5 -4 -3 -2 -1  0 +1 +2 +3 +4 +5 +6 +7 +8 +9

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).

HP FORTRAN 77/XL

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

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:

  • HP Business BASIC/XL Reference Manual (32715-90001)

  • HP C Reference Manual (92434-90001) and HP C/XL Reference Manual Supplement (31506-90001)

  • HP COBOL II/XL Programmer's Guide (31500-90002)

  • COBOL II Reference Manual (31500-90001) and COBOL II/XL Reference Manual Supplement (31500-90005)

  • HP FORTRAN 77/XL Reference Manual (31501-90010)

  • HP FORTRAN 77/XL Programmer's Guide (31501-90002)

  • HP Pascal Reference Manual (31502-90001)

  • HP Pascal Programmer's Guide (31502-90002)