SPL to HP C/XL Migration Guide (30231-90001)
4-10
In the second example, the DB area is equivalenced in a union with a
structure that places cell zero of reference array ABC_DEF at location
DB[10]. The pointer ABC is used to reference the array cells of ABC_REF,
thus overcoming the undefined subscript range problem presented by the
unbounded direct array in SPL. ABC_REF is a direct array.
POINTER Declaration
Table 4-4. POINTER Declaration
---------------------------------------------------------------------------------------------
|||
| SPL | HP C/XL Equivalent |
|||
---------------------------------------------------------------------------------------------
|||
|
pointer-declaration
:|
pointer-declaration
:|
|||
| [GLOBAL] [
type
] POINTER
ptr-defn
[,...] ;| [static] [
type
]
ptr-defn
[,...] ; |
|||
---------------------------------------------------------------------------------------------
|||
|
ptr-defn
:|
ptr-defn
:|
|||
| 1a.
ptr-id
| 1a. *
ptr-id
|
|||
| 1b.
ptr-id
:= @
ref-id
| 1b. *
ptr-id
=&
ref-id
|
|||
| 1c.
ptr-id
:= @
ref-id
(
index
) | 1c. *
ptr-id
=&
ref-id "[" index "]"
|
|||
| 2a.
ptr-id
=
ref-id
||
|||
| 2b.
ptr-id
=
ref-id sign offset
||
|||
| 3a.
ptr-id
=
register
||
|||
| 3b.
ptr-id
=
register sign offset
||
|||
|4.
ptr-id
=
offset
||
|||
---------------------------------------------------------------------------------------------
|||
| Default type: LOGICAL | Default type: int (= long int) |
|||
---------------------------------------------------------------------------------------------
|||
| Pointers are 16-bit values containing | Pointers are 32-bit values containing |
| DB-relative addresses. | standard MPE XL addresses. |
|||
| | Overlays of pointers and other data types |
| | must be recoded. |
|||
---------------------------------------------------------------------------------------------
|||
| Pointers may be initialized to addresses. | Same as SPL. |
|||
| INTEGER POINTER P := @IVAR; | short int *P = &IVAR; |
|||
| declares a pointer P, as a pointer to type | declares a pointer P, as a pointer to type |
| INTEGER data, and initializes it to the | short int data, and initializes it to the |
| address of the integer variable IVAR. | address of the short integer variable IVAR. |
|||
---------------------------------------------------------------------------------------------
|||
| Pointers may contain either byte addresses | Pointers always contain byte addresses, |
| or 16-bit word addresses, depending on the | regardless of the type of data being |
| data type. The rule is that BYTE pointers | pointed to. |
| contain byte addresses, and all other types | |
| contain word addresses. | Unlike SPL, HP C/XL automatically scales |
| | the operands used in pointer arithmetic, so |
| Consequently, many SPL programs contain | adding one--"*(
ptr
+1)"--to a type char |
| runtime code to "convert" between byte and | pointer increments it by one, but adding |