HP 3000 Manuals

Constant Types [ SPL to HP C/XL Migration Guide ] MPE/iX 5.0 Documentation


SPL to HP C/XL Migration Guide

Constant Types 

          Table 3-8.  Constant Types 

---------------------------------------------------------------------------------------------
|                                             |                                             |
|                     SPL                     |             HP C/XL Equivalent              |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| Numeric                                     | Numeric                                     |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| String                                      | String literal                              |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| One-byte string                             | Character                                   |
|                                             |                                             |
---------------------------------------------------------------------------------------------

SPL has two types of constants:  numeric and string.  You may have to
specify the type of the constant with a modifier to avoid errors when
mixing types.

HP C/XL has four types of constants:  integer, floating point, character,
and enumeration.  Type mixing is generally allowed in HP C/XL, so you do
not need to specify types except when you want to control word size.


NOTE HP C/XL does not permit a leading unary "+" sign, only a unary "-" sign.
Integer Constants Table 3-9. Integer Constants --------------------------------------------------------------------------------------------- | | | | SPL | HP C/XL Equivalent | | | | --------------------------------------------------------------------------------------------- | | | | Type: INTEGER | Type: short int | | | | --------------------------------------------------------------------------------------------- | | | | integer-constant: | integer-constant: | | | | | [sign] integer | [-] integer | | | | --------------------------------------------------------------------------------------------- Double Integer Constants Table 3-10. Double Integer Constants --------------------------------------------------------------------------------------------- | | | | SPL | HP C/XL Equivalent | | | | --------------------------------------------------------------------------------------------- | | | | Type: DOUBLE | Type: long int or int | | | | --------------------------------------------------------------------------------------------- | | | | double-integer-constant: | long-integer-constant: | | | | | [sign] integer D | [-] integer [L] | | | | --------------------------------------------------------------------------------------------- In HP C/XL, the L (specifying long int) is optional, since int and long int are equivalent and occupy 32 bits. The L may be lowercase. Based Constants Table 3-11. Based Constants --------------------------------------------------------------------------------------------- | | | | SPL | HP C/XL Equivalent | | | | --------------------------------------------------------------------------------------------- | | | | Type: INTEGER | Type: short int | | DOUBLE | long int or int | | LOGICAL | unsigned short int | | BYTE | unsigned char OR unsigned short | | | int | | REAL | float | | LONG | double | | | | --------------------------------------------------------------------------------------------- | | | | based-constant: | integer-constant: | | | | | [sign] % [( base )] value [type] | [-] 0octal-digits [L] | | | | | | [-] 0Xhex-digits [L] | | type: | | | is D, E, or L (for DOUBLE, REAL, or | Only octal and hexadecimal bases may be | | LONG); default is single word, usable as | specified. Numbers are signed decimal by | | INTEGER, LOGICAL, or BYTE. | default. The leading character is a zero. | | | A trailing L forces a long int constant. | | | The L and X may be lowercase. | | | | | | Floating point cannot be specified | | | directly. | | | | --------------------------------------------------------------------------------------------- | | | | Example: | Example: | | | | | %170033 octal | 0170033 octal | | %(16)F01B D hexadecimal | 0xF01B L hexadecimal | | %(2)11011011 binary | (No equivalent)) | | | | --------------------------------------------------------------------------------------------- Since HP C/XL can represent only octal, decimal, and hexadecimal values, based constants must be converted into one of those forms.
CAUTION Since MPE XL floating-point format is different from MPE V floating point, REAL and LONG based constants must be carefully translated if they are intended for arithmetic use.
Composite Constants Table 3-12. Composite Constants --------------------------------------------------------------------------------------------- | | | | SPL | HP C/XL Equivalent | | | | --------------------------------------------------------------------------------------------- | | | | Type: INTEGER | Type: short int | | DOUBLE | long int or int | | LOGICAL | unsigned short int | | BYTE | unsigned char OR unsigned short | | | int | | REAL | float | | LONG | double | | | | --------------------------------------------------------------------------------------------- | | | | composite-constant: | No direct equivalent. | | | | | [sign] "["length"/"value[,...]"]" | See "Based Constants" above. | | [type] | | | | | | | | | type | | | is D, E, or L (for DOUBLE, REAL, or | | | LONG); default is single word usable as | | | INTEGER, LOGICAL, or BYTE. | | | | | --------------------------------------------------------------------------------------------- | | | | Example: | Example: | | | | | +[3/2,12/%5252] (= %25252) | 025252 octal | | -[3/2,12/%5252] (= %152526) | -025252 octal | | | | ---------------------------------------------------------------------------------------------
CAUTION Since MPE XL floating-point format is different from MPE V floating point, REAL and LONG composite constants must be carefully translated if they are intended for arithmetic use.
Equated Integers Table 3-13. Equated Integer Constants --------------------------------------------------------------------------------------------- | | | | SPL | HP C/XL Equivalent | | | | --------------------------------------------------------------------------------------------- | | | | equated-integer: | defined-constant: | | | | | [sign] identifier [D] | [-] identifier | | | | --------------------------------------------------------------------------------------------- | | | | identifier | identifier | | is assigned a numeric value in an EQUATE | is assigned a literal value in a #define | | declaration. It represents a 16-bit | directive. The literal is inserted at | | INTEGER value. | the reference point. | | | | | If D is specified, the value is extended on | Note that, while SPL evaluates an equated | | the left with zeros to a 32-bit DOUBLE | integer when it is declared, HP C/XL | | value. | evaluates the literal when the reference is | | | compiled. | | | | --------------------------------------------------------------------------------------------- See "EQUATE Declaration and Reference". Real Constants Table 3-14. Real Constants --------------------------------------------------------------------------------------------- | | | | SPL | HP C/XL Equivalent | | | | --------------------------------------------------------------------------------------------- | | | | Type: REAL | Type: float | | | | --------------------------------------------------------------------------------------------- | | | | real-constant: | real-constant: | | 1. [sign] fixed-point-number [E power] | 1. [-] fixed-point-number [E power] | | 2. [sign] decimal-integer E power | 2. [-] decimal-integer E power | | 3. [sign] based|composite-integer E | 3. (No equivalent; convert to 1 or 2.) | | | The E may be in lowercase. | | | | ---------------------------------------------------------------------------------------------
CAUTION Since MPE XL floating-point format is different from MPE V floating point, REAL based and composite constants must be carefully translated if they are intended for arithmetic use.
Long Constants Table 3-15. --------------------------------------------------------------------------------------------- | | | | SPL | HP C/XL Equivalent | | | | --------------------------------------------------------------------------------------------- | | | | Type: LONG | Type: double | | | | --------------------------------------------------------------------------------------------- | | | | long-constant: | real-constant: | | 1. [sign] fixed-point-number L power | 1. [-] fixed-point-number [E power]; | | 2. [sign] decimal-integer L power | 2. [-] decimal-integer E power | | 3. [sign] based|composite-integer L | 3. (No equivalent; convert to 1 or 2.) | | | The E may be in lowercase. | | | | --------------------------------------------------------------------------------------------- HP C/XL uses the same representation for float and double constants.
CAUTION Since MPE XL floating-point format is different from MPE V floating point, LONG based and composite constants must be carefully translated if they are intended for arithmetic use.
Logical Constants Table 3-16. Logical Constants --------------------------------------------------------------------------------------------- | | | | SPL | HP C/XL Equivalent | | | | --------------------------------------------------------------------------------------------- | | | | Type: LOGICAL | Type: unsigned short int | | | | --------------------------------------------------------------------------------------------- | | | | TRUE (logical value: 65535; integer value: | No direct equivalent. May be specified | | -1) | with | | | | | | #define TRUE 1 | | | | --------------------------------------------------------------------------------------------- | | | | FALSE (zero) | No direct equivalent. May be specified | | | with | | | | | | #define FALSE 0 | | | | --------------------------------------------------------------------------------------------- | | | | INTEGER, LOGICAL, or BYTE constant: | Any numeric constant (including char): | | | | | * true if bit 15 is on (value is odd) | * true if value is nonzero. | | * false if bit 15 is off (value is even) | * false if value is zero. | | | | --------------------------------------------------------------------------------------------- String Constants Table 3-17. String Constants --------------------------------------------------------------------------------------------- | | | | SPL | HP C/XL Equivalent | | | | --------------------------------------------------------------------------------------------- | | | | Type: BYTE | Type: string literal OR unsigned char | | | | --------------------------------------------------------------------------------------------- | | | | string-constant: | string-literal: | | | | | "characters" | "characters" | | | | --------------------------------------------------------------------------------------------- | | | | characters | characters | | is one or more ASCII characters (up to | is zero or more ASCII characters. A | | 127). A quotation mark (""") within | quotation mark, """, within characters is | | characters is doubled. | represented by the "escape sequence" | | | "\"", an apostrophe, "'", by "\'", and a | | | backslash, "\", by "\\". | | | | --------------------------------------------------------------------------------------------- | | | | For example, the string | For example, the string | | | | | He said, "Hi." | He said, "Hi." | | | | | is entered as: | is entered as: | | | | | "He said, ""Hi.""" | "He said, \"Hi.\"" | | | | --------------------------------------------------------------------------------------------- | | | | Characters are stored two to the 16-bit | Characters are stored as a series of 8-bit | | word, left justified. | bytes. The string literal is terminated by | | | HP C/XL with the ASCII NUL character ('\0', | | | numeric value 0). This fact is used by | | | many HP C/XL string manipulation functions | | | that might be used to emulate SPL string | | | operations. | | | | --------------------------------------------------------------------------------------------- HP C/XL also has a character constant, in the form: 'char' where char is a single character, or a special escape sequence using a leading "\" character, such as those shown above. Escape sequences can be used in character and string constants to represent any of the 256 ASCII character codes. Consult the HP C Reference Manual for further details.


MPE/iX 5.0 Documentation