HP 3000 Manuals

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


SPL to HP C/XL Migration Guide

Expression Types 

          Table 5-1.  Expression Types 

---------------------------------------------------------------------------------------------
|                                             |                                             |
|                     SPL                     |             HP C/XL Equivalent              |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| Variables on either side of an operator     | Variable types may be mixed in expressions. |
| must be of the same type.  Type transfer    | Automatic type conversion is performed      |
| functions are used to convert types.        | prior to execution of an operator.  See "HP |
|                                             | C/XL Rules for Automatic Numeric Type       |
|                                             | Conversion" in this chapter.                |
|                                             |                                             |
|                                             | A "cast" operator may be used to force an   |
|                                             | expression to a desired data type, perhaps  |
|                                             | for an actual parameter to a function.      |
|                                             |                                             |
---------------------------------------------------------------------------------------------

| The type transfer functions are the names   | The corresponding cast operators are        |
| of the simple variable types, plus two      | similar to SPL, except that the type names  |
|                                             |                                             |
| additions, in the function form:            | are enclosed in parentheses:                |
|                                             |                                             |
|     BYTE ( double | integer | logical )     |     (unsigned char) (expression)            |
|     DOUBLE ( byte | integer | logical )     |     (long int) (expression)                 |
|         FIXR ( real )  rounds to DOUBLE     |         (No equivalent)                     |
|         FIXT ( real )  truncates to DOUBLE  |         (long int) (expression)             |
|     INTEGER ( byte | double | logical )     |     (short int) (expression)                |
|     LOGICAL ( byte | double | integer )     |     (unsigned short int) (expression)       |
|     LONG ( double | real )                  |     (double) (expression)                   |
|     REAL ( byte | double | integer |        |     (float) (expression)                    |
| logical | long )                            |                                             |
|                                             | The expression may have any appropriate     |
| byte, double, integer, logical, long, and   | character or numeric value.  The            |
| real are the types permitted in the         | parentheses around expression may be        |
| particular functions.                       | omitted if it is a single entity.           |
|                                             | Conversion from float or double to any char |
| Sometimes more than one function is         | or int type is by truncation.  There is no  |
| required, as in the conversion from REAL to | rounding function.  HP C/XL also allows     |
| INTEGER, which requires either              | other simple data and pointer types in cast |
| "INTEGER(FIXR(real))" or                    | operations.                                 |
| "INTEGER(FIXT(real))".                      |                                             |
---------------------------------------------------------------------------------------------

HP C/XL Rules for Automatic Numeric Type Conversion 

As an expression is evaluated, HP C/XL performs automatic data type
conversions on the operands.  First, each operand is evaluated and
converted, according to Table 5-2.

          Table 5-2.  Automatic Unary Type Conversions 

---------------------------------------------------------------------------------------------
|                                             |                                             |
|                Original Type                |                Converted to                 |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| char                                        | int                                         |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| short int                                   | int                                         |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| unsigned char                               | unsigned int                                |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| unsigned short int                          | unsigned int                                |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| float                                       | double 1                                     |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| int                                         | int 2                                        |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| long int                                    | long int 2                                   |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| unsigned int                                | unsigned int 2                               |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| unsigned long int                           | unsigned long int 2                          |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                                                                           |
|   1   This conversion from float to double may be prevented with the HP C/XL compiler      |
|    option "-Wc,-r".  See the HP C/XL Reference Manual Supplement for details.             |
|                                                                                           |
| 2   These types are not converted.  They are included here for completeness.               |
|                                                                                           |
---------------------------------------------------------------------------------------------

Second, arithmetic operands in binary operations are converted.  If the
two operands are the same type, the conversion is complete.  Otherwise,
the process continues row-by-row through Table 5-3 until a conversion
makes the operand types equal.

          Table 5-3.  Automatic Binary Type Conversions 

------------------------------------------------------------------------------------------------
|                          |                          |                                        |
|       One Operand        |      Other Operand       |               Conversion               |
|                          |                          |                                        |
------------------------------------------------------------------------------------------------
|                          |                          |                                        |
| double                   | any type                 | Other becomes double                   |
|                          |                          |                                        |
------------------------------------------------------------------------------------------------
|                          |                          |                                        |
| float                    | any type                 | Other becomes float                    |
|                          |                          |                                        |
------------------------------------------------------------------------------------------------
|                          |                          |                                        |
| unsigned long int        | any type                 | Other becomes unsigned long int        |
|                          |                          |                                        |
------------------------------------------------------------------------------------------------
|                          |                          |                                        |
| long int                 | unsigned int             | Both become unsigned long int          |
|                          |                          |                                        |
------------------------------------------------------------------------------------------------
|                          |                          |                                        |
| long int                 | not unsigned int         | Other becomes long int                 |
|                          |                          |                                        |
------------------------------------------------------------------------------------------------

When a value is stored (as in an assignment), it is converted to the
destination type.



MPE/iX 5.0 Documentation