POINTER Declaration [ SPL to HP C/XL Migration Guide ] MPE/iX 5.0 Documentation
SPL to HP C/XL Migration Guide
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 |
| word addresses, generally via LSL and LSR | one to a type short int pointer will |
| shift operators. This also affects pointer | increment it by two, thus pointing to the |
| arithmetic, since adding one to a byte | next type short int variable. |
| pointer increments its address to the next | |
| byte, but adding one to an integer pointer | While this is more convenient than the SPL |
| increments its address to the next word. A | convention, it will require careful |
| pointer to type DOUBLE or REAL must be | examination of any SPL code being converted |
| incremented by two to advance it to the | to HP C/XL to guarantee accurate pointer |
| next DOUBLE or REAL variable. A pointer to | arithmetic operations. |
| type LONG must be incremented by four. | |
| | |
------------------------------------------------------------------------------------------------
| | |
| A pointer location may be equated to a | No direct equivalent. |
| location relative to another variable or a | |
| register. | Locations may be equated with a union |
| | declaration or with pointer arithmetic. |
| | |
------------------------------------------------------------------------------------------------
MPE/iX 5.0 Documentation