Formatting Data in Programs [ DATA TYPES CONVERSION Programmer's Guide ] MPE/iX 5.0 Documentation
DATA TYPES CONVERSION Programmer's Guide
Formatting Data in Programs
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 boundaries 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, following, shows corresponding data types in the different NM
languages:
Table 2-5. Correspondence of Data Types Across Languages: Intrinsics, BASIC, and C
-------------------------------------------------------------------------------------------------
| | | | |
| Data Type | Intrinsics | HP Business | HP C/XL |
| | | BASIC/XL | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Character | C | $ | CHAR or |
| | | dimension as | UNSIGNED |
| | | 1 character | CHAR |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Integer: | U16 | N/A | UNSIGNED |
| 16-bit | | | SHORT INT |
| unsigned | | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Integer: | U32 | N/A | UNSIGNED INT |
| 32-bit | | | or UNSIGNED |
| unsigned | | | LONG INT |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Integer: | U64 | N/A | N/A |
| 64-bit | | | |
| unsigned | | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Integer: | I16 | SHORTINT | SHORT INT |
| 16-bit | | or subrange | |
| signed | | [-32768..32767] | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Integer: | I32 | INTEGER | INT or ENUM |
| 32-bit | | | |
| signed | | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Integer: | I64 | N/A | N/A |
| 64-bit | | | |
| signed | | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Real | R32 | SHORTREAL | FLOAT |
| 32-bit | | | |
| (Single- | | | |
| Precision) | | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Real | R64 | REAL | DOUBLE |
| 64-bit | | | |
| (Double- | | | |
| Precision) | | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Decimal: Packed | N/A | N/A | N/A |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Decimal: | N/A | N/A | N/A |
| Unpacked | | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Decimal: | N/A | Decimal or | N/A |
| Floating- | | Short Decimal | |
| Point | | | |
| | | | |
-------------------------------------------------------------------------------------------------
Table 2-6. Correspondence of Data Types Across Languages: COBOL, FORTRAN, and Pascal
--------------------------------------------------------------------------------------------------
| | | | |
| Data Type | HP COBOL | HP FORTRAN | HP Pascal/XL |
| | II/XL | 77/XL | |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Character | DISPLAY | CHARACTER | CHARACTER |
| | or group item | | |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Integer: | PIC S9 to | LOGICAL OR | 0..65535 |
| 16-bit | PIC S9(4) | LOGICAL*2 | or any 16-bit |
| unsigned | COMP | | SUBRANGE |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Integer: | PIC S9(5) to | LOGICAL OR | Any 32-bit |
| 32-bit | PIC S9(9) | LOGICAL*4 | subrange |
| unsigned | COMP | | |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Integer: | PIC S9(10) to | N/A | N/A |
| 64-bit | PIC S9(18) | | |
| unsigned | COMP | | |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Integer: | PIC S9 to | INTEGER or | SHORTINT or |
| 16-bit | PIC S9(4) | INTEGER *2 | any 16-bit |
| signed | COMP | | subrange |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Integer: | PIC S9(5) to | INTEGER or | INTEGER or |
| 32-bit | PIC S9(9) | INTEGER *4 | any 32-bit |
| signed | COMP | | subrange |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Integer: | PIC S9(10) to | N/A | N/A |
| 64-bit | PIC S9(18) | | |
| signed | COMP | | |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Real | N/A | REAL or | REAL |
| 32-bit | | REAL*4 | |
| (Single- | | | |
| Precision) | | | |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Real | N/A | DOUBLE | LONGREAL |
| 64-bit | | PRECISION | |
| (Double- | | or REAL*8 | |
| Precision) | | | |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Decimal: Packed | COMP-3 | N/A | N/A |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Decimal: | DISPLAY | N/A | N/A |
| Unpacked | | | |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Decimal: | N/A | N/A | N/A |
| Floating-Point | | | |
| | | | |
--------------------------------------------------------------------------------------------------
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/XL 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)
MPE/iX 5.0 Documentation