HP 3000 Manuals

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


SPL to HP C/XL Migration Guide

Variables 

          Table 5-4.  Variables 

-------------------------------------------------------------------------------------------------
|                                             |                                                 |
|                     SPL                     |               HP C/XL Equivalent                |
|                                             |                                                 |
-------------------------------------------------------------------------------------------------
|                                             |                                                 |
| Syntax of a variable in an expression:      | Syntax of a variable in an expression:          |
|                                             |                                                 |
|      1. simple-id                           |      1. simple-id                               |
|                                             |                                                 |
|      2. array/ptr-id                        |      2. array/ptr-id "["0"]" OR *array/ptr-id   |
|                                             |                                                 |
|      3. array/ptr-id ( index )              |      3. array/ptr-id "[" index "]"              |
|                                             |                                                 |
|      4. @identifier                         |      4. &identifier                             |
|                                             |                                                 |
|      5. @array/ptr-id                       |      5. &array/ptr-id "[" 0 "]" OR array/ptr-id |
|                                             |                                                 |
|      6. @array/ptr-id ( index )             |      6. &array/ptr-id "[" index "]"             |
|                                             |                                                 |
|      7. TOS                                 |      7. No equivalent.                          |
|                                             |                                                 |
|      8. ABSOLUTE ( index )                  |      8. No equivalent.                          |
|                                             |                                                 |
-------------------------------------------------------------------------------------------------
|                                             |                                                 |
| Syntax of a variable on the left of an      | Syntax of a variable on the left of an          |
| assignment operator (:=):                   | assignment operator (=):                        |
|                                             |                                                 |
|      a. simple-id                           |      a. simple-id                               |
|                                             |                                                 |
|      b. array/ptr-id                        |      b. array/ptr-id "[" 0" ]" OR *array/ptr-id |
|                                             |                                                 |
|      c. array/ptr-id ( index )              |      c. array/ptr-id "[" index "]"              |
|                                             |                                                 |
|      d. @ptr-id                             |      d. ptr-id                                  |
|                                             |                                                 |
|      e. TOS                                 |      e. No equivalent.                          |
|                                             |                                                 |
|      f. ABSOLUTE ( index )                  |      f. No equivalent.                          |
|                                             |                                                 |
-------------------------------------------------------------------------------------------------
|                                             |                                                 |
| The address operator, "@", specifies the    | The address operator is "&".                    |
| location of a variable, rather than its     |                                                 |
| contents.                                   | An unsubscripted array-id or pointer-id is      |
|                                             | an address rather than cell zero; either        |
| An unsubscripted pointer-id or array-id is  | add the subscript or use the "*" operator.      |
| assumed to be subscripted by zero.          |                                                 |
|                                             |                                                 |
| See "Addresses (@) and Pointers" below.     |                                                 |
|                                             |                                                 |
-------------------------------------------------------------------------------------------------
|                                             |                                                 |
| The assignment operator is ":=".            | The assignment operator is "=".                 |
|                                             |                                                 |
|                                             | Note:  The HP C/XL assignment operator,         |
|                                             | "=", is the SPL equality operator.              |
|                                             |                                                 |
-------------------------------------------------------------------------------------------------
|                                             |                                                 |
| Indexes are enclosed in parentheses, "( )". | Indexes are enclosed in brackets, "[ ]".        |
|                                             |                                                 |
-------------------------------------------------------------------------------------------------

SPL allows assignment to the array-id of an indirect array since it is
really a pointer.  HP C/XL does not permit assignments to any array-id.
You may simulate the process by using a pointer to array cell zero.  (See
"ARRAY Declaration".)

The reserved word TOS and the ABSOLUTE function cannot be translated (see
below).  Their operations must be recoded entirely.

TOS 

          Table 5-5.  TOS 

---------------------------------------------------------------------------------------------
|                                             |                                             |
|                     SPL                     |             HP C/XL Equivalent              |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| TOS                                         | No equivalent.                              |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| Refers to the top of the hardware stack.    | You could write routines to emulate the     |
|                                             | hardware stack, but a better solution is to |
|                                             | recode SPL programs to eliminate stack      |
|                                             | references.                                 |
|                                             |                                             |
---------------------------------------------------------------------------------------------

Addresses (@) and Pointers 

          Table 5-6.  Addresses and Pointers 

---------------------------------------------------------------------------------------------
|                                             |                                             |
|                     SPL                     |             HP C/XL Equivalent              |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| The address operator, "@", before a simple  | The address operator, "&", before any       |
| variable-id yields the address of the       | variable-id yields the address of the       |
| variable instead of its contents.  If "@"   | variable.  Before a subscripted pointer-id  |
| precedes an array or pointer reference, it  | or array-id, it yields the address of the   |
| yields the address of cell zero or of the   | referenced location.                        |
| indexed location if indexed.                |                                             |
|                                             | The dereference operator, "*", before a     |
| If "@" precedes an unsubscripted pointer-id | pointer expression yields the value of the  |
| or indirect array-id on the left side of    | referenced location.  An array-id can be    |
| the assignment operator, ":=", the          | used as a pointer in an expression.         |
| right-side expression is stored as the new  |                                             |
| address value in the identifier.            | An unsubscripted pointer-id or array-id     |
|                                             | yields the address in the identifier.       |
| This leads to a potentially confusing       |                                             |
| feature of SPL:                             |                                             |
|                                             |                                             |
|      @ARRAYNAME := @NEWARRAY;               |                                             |
|                                             |                                             |
| This assigns the address of NEWARRAY(0) to  |                                             |
| array variable ARRAYNAME. Consequently,     |                                             |
| ARRAYNAME(0) and NEWARRAY(0) both refer to  |                                             |
| the same location.                          |                                             |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| All SPL addresses are 16-bit quantities     | All HP C/XL addresses are 32-bit            |
| that may be stored in integer and logical   | quantities.                                 |
| variables.  It is preferable to store       |                                             |
| addresses in pointer variables, but the     | In many cases, the SPL logical arrays may   |
| lack of pointer "arrays" in SPL has led to  | be converted to HP C/XL pointer arrays      |
| some applications that store addresses in   | without difficulty.                         |
| logical arrays.                             |                                             |
|                                             |                                             |
---------------------------------------------------------------------------------------------

Table 5-7 compares various uses of the SPL "@" operator and the
equivalent HP C/XL assignment.

          Table 5-7.  Assignments Using Pointers and Simple Variables 
----------------------------------------------------------------------------------------------
|                              |                              |                              |
|             SPL              |           HP C/XL            |          Operation           |
|                              |                              |                              |
----------------------------------------------------------------------------------------------
|                              |                              |                              |
|  POINTER P1,P2;              | unsigned int *P1,*P2;        | Declarations                 |
|                              |                              |                              |
|  LOGICAL V3;                 | unsigned int V3;             |                              |
|                              |                              |                              |
----------------------------------------------------------------------------------------------
|                              |                              |                              |
|  P1 :=  P2                   | *P1 = *P2                    | Object of P2 stored in       |
|                              |                              | object of P1                 |
|                              |                              |                              |
|  P1 := @P2                   | *P1 =  P2                    | Address in P2 stored in      |
|                              |                              | object of P1                 |
|                              |                              |                              |
| @P1 := @P2                   |  P1 =  P2                    | Address in P2 stored in P1   |
|                              |                              |                              |
| @P1 :=  P2                   |  P1 = *P2                    | Object of P2 stored in P1    |
|                              |                              |                              |
----------------------------------------------------------------------------------------------
|                              |                              |                              |
|  P1 :=  V3                   | *P1 =  V3                    | Value of V3 stored in object |
|                              |                              | of P1                        |
|                              |                              |                              |
|  P1 := @V3                   | *P1 = &V3                    | Address of V3 stored in      |
|                              |                              | object of P1                 |
|                              |                              |                              |
| @P1 := @V3                   |  P1 = &V3                    | Address of V3 stored in P1   |
|                              |                              |                              |
| @P1 :=  V3                   |  P1 =  V3                    | Value of V3 stored in P1     |
|                              |                              |                              |
----------------------------------------------------------------------------------------------
|                              |                              |                              |
|  V3 :=  P2                   |  V3 = *P2                    | Object of P2 stored in V3    |
|                              |                              |                              |
|  V3 := @P2                   |  V3 =  P2                    | Address in P2 stored in V3   |
|                              |                              |                              |
----------------------------------------------------------------------------------------------

Absolute Addresses 

          Table 5-8.  Absolute Addresses 

---------------------------------------------------------------------------------------------
|                                             |                                             |
|                     SPL                     |             HP C/XL Equivalent              |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| absolute-address:                           | No equivalent.                              |
|                                             |                                             |
|      ABSOLUTE ( index )                     |                                             |
|                                             |                                             |
---------------------------------------------------------------------------------------------

The use of absolute addresses in MPE V is entirely system-dependent, and
only permitted in privileged mode.  They must be recoded in HP C/XL.



MPE/iX 5.0 Documentation