|
|
DATA TYPES CONVERSION Programmer's Guide: HP 3000 MPE/iX Computer Systems > Chapter 1 IntroductionConverting Data Types |
|
You may want to change the form of information. Data output can be created by one MPE process that cannot be used in another without translation or conversion. Plan for conversion if you pass data to be used in the following situations:
Language commands, system intrinsics, and compiler library routines help you convert between types and formats. You may need to make different types of data together compatible to use them in a program. For example, to calculate the total cost of a product, you may need to multiply a price by the number sold. If the price is stored as ASCII data type and the number sold is stored as integer, one of them will have to be converted to the same data type as the other. Subroutines are already available for many common conversions. There are also intrinsics at the system level, and commands within programming languages to convert. Chapter 2 “Formatting Data Types” defines the NM primitive types and provides their bit maps. Chapter 3 “Converting Data Types” gives some conversion methods. MPE V/E and MPE XL in Compatibility Mode (MPE XL CM) are based on a 16-bit word; MPE XL in Native Mode (MPE XL NM) is based on a 32-bit word. Some data types are represented differently. For example, a real number in a CM-compiled program will, by default, be in HP3000 format. The same real value in an NM-compiled program will, by default, be in IEEE format. If conversion is necessary, consider re-compiling routines, writing subroutines to reformat, or using system intrinsics. The high-level languages do not all recognize the same primitive data types. COBOL uses the decimal data type, which is not recognized by Pascal; however, the floating-point real number type is mutually understood by Pascal and MPE XL, but is not recognized by COBOL. Languages may define their own complex data types that cannot be interpreted by other languages. If you pass data between routines that do not use the same types or formats, you lose integrity and meaning. The receiving routine may not be able to read the data at all. It may divide the bits it reads into the wrong size chunks. It may interpret the arrangement of bits by its own formatting conventions. The result could be completely different information than you intended. You must plan for conversion if a program uses a subroutine written in a language with incompatible types. Some languages have commands that translate directly as data is read in and written out. You may need to write a routine to transform the data indirectly. Remember that all the data used in any MPE language is a primitive data type or is based on a primitive type. You could write one routine to translate data from the first language types into primitive system types, and then another routine to translate those system types into a form the second language can use. |
|