Local Declarations [ SPL to HP C/XL Migration Guide ] MPE/iX 5.0 Documentation
SPL to HP C/XL Migration Guide
Local Declarations
Table 8-6. Local Declarations
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
| All variables declared within a procedure | Same as SPL. |
| are "local" to that procedure; they may not | |
| be referenced outside of the scope of the | |
| procedure. | |
| | |
---------------------------------------------------------------------------------------------
Table 8-7 lists the three types of local variables in SPL, along with
their HP C/XL equivalents.
Table 8-7. Local Variable Storage Classes
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
| standard | [auto] (the default case) |
| | |
---------------------------------------------------------------------------------------------
| | |
| OWN | static |
| | |
---------------------------------------------------------------------------------------------
| | |
| EXTERNAL | extern |
| | |
---------------------------------------------------------------------------------------------
OWN Variables
Table 8-8. OWN Variables
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
| Standard variables declared local to a | Same as SPL, using auto variables (the |
| procedure are assigned new space each time | default). |
| a procedure is invoked, the space being | |
| released when the procedure is exited. | |
| | |
---------------------------------------------------------------------------------------------
| | |
| If a variable is declared as OWN, space is | Same as SPL, using static variables. |
| allocated outside of the dynamic scope of | |
| the procedure, in the DB-relative area. | |
| | |
| The variable is still known only to the | |
| procedure, and it retains its value between | |
| successive calls to the procedure. If an | |
| OWN variable is initialized, it is | |
| initialized once, at the start of the | |
| program, not every time the procedure is | |
| called. | |
| | |
---------------------------------------------------------------------------------------------
Local Simple Variable Declarations
Standard Local Variables.
Table 8-9. Standard Local Simple Variables
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
| standard-local-simple-variable-declaration: | simple-variable-declaration: |
| type variable-decl [,...] ; | [type] variable-decl [,...] ; |
| | |
---------------------------------------------------------------------------------------------
| | |
| variable-decl: | variable-decl: |
| 1a. variable-id | 1a. variable-id |
| 1b. variable-id := initial-value | 1b. variable-id = initial-value |
| 2a. variable-id = register | |
| 2b. variable-id = register sign offset | |
| 3a. variable-id = ref-id | |
| 3b. variable-id = ref-id sign offset | |
| | |
---------------------------------------------------------------------------------------------
| | |
| type is required. | Default type: int (= long int) |
| | |
---------------------------------------------------------------------------------------------
| | |
| Storage is allocated each time the procedure| Same as SPL. |
| is called. If an initial value is defined, | |
| it will be assigned each time the procedure | |
| is called. | |
| | |
---------------------------------------------------------------------------------------------
Simple variables in forms 2 and 3 are usually various types of data
equivalences. They may be converted to pointers or union equivalences,
depending on the requirements of the program. See "ARRAY Declaration"
for further examples.
OWN Simple Variables.
Table 8-10. OWN Local Simple Variables
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
| own-simple-variable-declaration: | static-simple-variable-declaration: |
| | |
| OWN type variable-decl [,...] ; | static [type] variable-decl [,...] ; |
| | |
---------------------------------------------------------------------------------------------
| | |
| variable-decl: | variable-decl: |
| | |
| 1a. variable-id | 1a. variable-id |
| | |
| 1b. variable-id := initial-value | 1b. variable-id = initial-value |
| | |
---------------------------------------------------------------------------------------------
| | |
| type is required. | Default type: int (= long int) |
| | |
---------------------------------------------------------------------------------------------
| | |
| An OWN local variable is allocated storage | Similar to SPL, using a static local |
| global to the procedure, in the DB-relative | variable. |
| area. It retains its values between | |
| successive calls to the procedure. | |
| | |
| If an initial value is declared for an OWN | |
| variable, the variable is initialized once, | |
| at the start of the program, not every time | |
| the procedure is called. | |
| | |
---------------------------------------------------------------------------------------------
EXTERNAL Simple Variables.
Table 8-11. EXTERNAL Local Simple Variables
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
| external-simple-variable-declaration: | extern-simple-variable-declaration: |
| | |
| EXTERNAL type variable-id [,...] ; | extern [type] variable-id [,...] ; |
| | |
---------------------------------------------------------------------------------------------
| | |
| type is required. | Default type: int (= long int) |
| | |
---------------------------------------------------------------------------------------------
| | |
| An EXTERNAL local variable refers to a | Similar to SPL. |
| global variable that is declared GLOBAL in | |
| a separate compilation unit. The storage | An extern local variable refers to a global |
| is allocated by the other unit. | variable that is not declared static in a |
| | separate compilation unit. The storage is |
| | allocated by the unit that defines it. |
| | |
---------------------------------------------------------------------------------------------
See "Types of Declarations" for more detail.
Local Array Declarations
Standard Local Arrays.
Table 8-12. Standard Local Arrays
----------------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
----------------------------------------------------------------------------------------------------
| | |
| standard-local-array-declaration: | array-declaration: |
| | |
| [type] ARRAY | 1b with lower = 0. |
| | |
| [local-array-decl ,] [...] | [type] array-id "[" cells "]" ; |
| | |
| {local-array-decl | |
| constant-array-decl} ; | 1a; 1b with lower <> 0. |
| | |
| | [type] array-ref "[" cells "]" ; |
| local-array-decl: | |
| | |
| 1a. array-id ( lower : upper ) | [type] * array-id |
| | |
| 1b. array-id ( lower : upper ) = Q | = & array-ref "[" index "]" ; |
| | |
| 2. array-id ( var-lower : var-upper ) | |
| | 10 with lower = 0. |
| 3. array-id (@) = Q | |
| | static [type] array-id "[" cells "]" init ; |
| 4. array-id (*) = Q | |
| | |
| 5a. array-id (@) | 10 with lower <> 0. |
| | |
| 5b. array-id (@) = register sign offset | static [type] array-ref "[" cells "]" init ; |
| | |
| 6. array-id (*) | |
| | static [type] * array-id |
| 7. array-id (*) = register sign offset | |
| | = & array-ref "[" index "]" ; |
| 8a. array-id (*) = ref-id | |
| | |
| 8b. array-id (*) = ref-id sign offset | init: |
| | = "{" value [,...] "}" |
| 9. array-id (*) = ref-id ( index ) | |
| | |
| | index: |
| constant-array-decl: | Cell number in array-ref of cell that |
| | corresponds to cell zero in SPL array. |
| 10. array-id ( lower : upper ) = PB | |
| | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
| := value-group [,...] | |
| | |
| | The other SPL forms establish an |
| value-group: | equivalence relative to other declared data |
| | (not just arrays). Depending on their |
| {initial-value | actual use, they may be converted to HP |
| repeat-factor ( initial-value[,...] )} | C/XL pointer or union types, or #define |
| | directives. If their relationships are |
| | fairly simple, pointers can be used. |
| | |
----------------------------------------------------------------------------------------------------
| | |
| Default type: LOGICAL | Default type: int (= long int) |
| | |
----------------------------------------------------------------------------------------------------
The general rules for global array declarations also apply to local array
declarations. See "ARRAY Declaration" for details and other conversion
suggestions.
Standard arrays declared local to a procedure are allocated each time the
procedure is called, and may not be referenced outside of the procedure.
Standard arrays (except for form 10) cannot be initialized.
Array form 10 is a special constant array declaration that is stored in
the code segment and cannot be modified while the program is running.
The suggested conversion to a static array (equivalent to an OWN array)
should be effective. Care must be taken with subsequent code changes,
since the converted static array can be modified by the program.
Summary of SPL Local Array Forms.
1a. Indirect; bounded; variable is pointer to cell zero; pointer in
next Q-relative location; pointer IS allocated; array begins in
next Q+ location; array IS allocated.
1b. Direct; bounded; variable is cell zero; lower in next Q+ location;
array IS allocated.
2. Indirect; variable bounds; variable is pointer to cell zero;
pointer IS allocated when procedure is called; array IS allocated
when procedure is called.
3. Indirect; unbounded; variable is pointer to cell zero; pointer in
next Q-relative location; pointer NOT allocated; array NOT
allocated.
4. Direct; unbounded; variable is cell zero; cell zero in next
Q-relative location; array NOT allocated.
5a. Indirect; unbounded; variable is pointer to cell zero; pointer in
next Q-relative location; pointer IS allocated; array NOT
allocated.
5b. Indirect; unbounded; variable is pointer to cell zero; pointer in
specified DB-, Q-, or S-relative location; pointer NOT allocated;
array NOT allocated.
6. Indirect; unbounded; variable is pointer to cell zero; pointer in
next Q-relative location; pointer IS allocated; array NOT
allocated.
7. Direct; unbounded; variable is cell zero; cell zero in specified
DB-, Q-, or S-relative location; array NOT allocated.
8a. Direct (if ref-id is direct array or simple variable); unbounded;
variable is cell zero; cell zero in specified location; array NOT
allocated.
Indirect (if ref-id is pointer or indirect array); unbounded;
variable is pointer to cell zero; cell zero in ref-id location;
pointer in next Q-relative location IF one %id% type is BYTE and
other is not; ELSE pointer location shared with ref-id; pointer IS
allocated; array NOT allocated.
8b. Direct; unbounded; variable is cell zero; cell zero in specified
location; array NOT allocated.
9. Direct (if ref-id is direct array); unbounded; variable is cell
zero; cell zero in specified location; array NOT allocated.
Indirect (if ref-id is pointer or indirect array); unbounded;
variable is pointer to cell zero; cell zero in specified location;
pointer in next Q-relative location IF specified location is not
ref-id cell zero OR IF one array is BYTE and other is not; ELSE
pointer location shared with ref-id; pointer IS allocated; array
NOT allocated.
Array forms 1a, 1b, 3, 4, 5a, 5b, 6, 7, 8a, 8b, and 9 correspond directly
to global array forms 1a, 1b, 2a, 3a, 4a, 4b, 5, 6, 7a, 7b, and 8,
respectively, except that they are Q-relative rather than DB-relative.
Array forms 3, 4, 5, 6, 7, 8, and 9 imply various methods of data
equivalencing or "overlays".
Only array form 10 may be initialized.
Comparison of Specific Local Array Declarations. See also "ARRAY
Declaration".
Array Format 2: Bounded Indirect Variable Array.
-----------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
-----------------------------------------------------------------------------------------------
| | |
| | No direct equivalent. |
| INTEGER ARRAY ABC ( LOW'VAR : HIGH'VAR ) | |
| This is an SPL "indirect" array with | Dynamic arrays are not allowed, but there |
| variable bounds. The bounds are evaluated | are library routines, such as malloc, to |
| each time the procedure is called, and | allocate memory dynamically and assign an |
| storage is allocated accordingly. | address to an array name. See the HP C/XL |
| | Library Reference Manual for details. |
| | |
-----------------------------------------------------------------------------------------------
Array Format 10: Bounded Direct Constant Array.
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
| | |
| REAL ARRAY ABC(0:9) = PB | static float ABC [10] |
| := 1,2,3,4,5,6,7,8,9,10; | = {1,2,3,4,5,6,7,8,9,10}; |
| This is a "constant" array. It is | This is not an exact equivalent. There is |
| initialized in the code segment and cannot | no protection against inadvertent |
| not be modified. | modification. |
| | |
---------------------------------------------------------------------------------------------
OWN Local Arrays.
Table 8-13. OWN Local Arrays
----------------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
----------------------------------------------------------------------------------------------------
| | |
| own-array-declaration: | static-array-declaration: |
| | |
| OWN [type] ARRAY | 1 with lower = 0. |
| | |
| [own-array-decl ,] [...] | static [type] array-id "[" cells "]" ; |
| | |
| init-own-array-decl ; | |
| | 1 with lower <> 0. |
| | |
| own-array-decl: | static [type] array-ref "[" cells "]" ; |
| | |
| 1. array-id ( lower : upper ) | |
| | static [type] * array-id |
| | |
| init-own-array-decl: | = & array-ref "[" index "]" ; |
| | |
| 2. array-id ( lower : upper ) | |
| | 2 with lower = 0. |
| := value-group [,...] | |
| | static [type] array-id "[" cells "]" init ; |
| | |
| value-group: | |
| | 2 with lower <> 0. |
| {initial-value | |
| repeat-factor ( initial-value[,...] )} | static [type] array-ref "[" cells "]" init ; |
| | |
| | |
| | static [type] * array-id |
| | |
| | = & array-ref "[" index "]" ; |
| | |
| | |
| | init: |
| | = "{" value [,...] "}" |
| | |
| | |
| | index: |
| | Cell number in array-ref of cell that |
| | corresponds to cell zero in SPL array. |
| | |
----------------------------------------------------------------------------------------------------
| | |
| Default type: LOGICAL | Default type: int (= long int) |
| | |
----------------------------------------------------------------------------------------------------
| | |
| An OWN local array is allocated storage | Same as SPL, using a static local array. |
| global to the procedure, in the DB-relative | |
| area. It retains its values between | |
| successive calls to the procedure. | |
| | |
| If an initial value is declared for an OWN | |
| array, the variable is initialized once, at | |
| the start of the program, not every time | |
| the procedure is called. | |
| | |
----------------------------------------------------------------------------------------------------
EXTERNAL Local Arrays.
Table 8-14. EXTERNAL Local Arrays
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
| external-array-declaration: | extern-array-declaration: |
| | |
| EXTERNAL [type] ARRAY | Direct with lower = 0. |
| | |
| {array-id {(*) | extern [type] array-id "[" "]" ; |
| (@)}} [,...] ; | |
| | |
| | Indirect, or direct with lower <> 0. |
| (*) signifies a direct array. | |
| | extern [type] * array-id |
| | |
| (@) signifies an indirect array. | |
| | |
---------------------------------------------------------------------------------------------
| | |
| Default type: LOGICAL | Default type: int (= long int) |
| | |
---------------------------------------------------------------------------------------------
| | |
| An EXTERNAL local array refers to a global | Similar to SPL. |
| array that is declared GLOBAL in a separate | |
| compilation unit. The storage is allocated | An extern local array refers to a global |
| by the other unit. | array that is not declared static in a |
| | separate compilation unit. The storage is |
| | allocated by the other unit. |
| | |
---------------------------------------------------------------------------------------------
See "Types of Declarations" for further details.
Local Pointer Declarations
See "POINTER Declaration" for further details.
Standard Local Pointers.
Table 8-15. Standard Local Pointers
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
| standard-local-pointer-declaration: | pointer-declaration: |
| | |
| [type] POINTER ptr-decl [,...] ; | [type] ptr-decl [,...] ; |
| | |
| | |
| ptr-decl: | ptr-decl: |
| | |
| 1a. ptr-id | 1a. * ptr-id |
| | |
| 1b. ptr-id := @ref-id | 1ba. * ptr-id = ref-id |
| | |
| 1c. ptr-id := @ref-id ( index ) | 1bv. * ptr-id = & ref-id |
| | |
| 2a. ptr-id = ref-id | 1c. * ptr-id = & ref-id "[" index "]" |
| | |
| 2b. ptr-id = ref-id sign offset | |
| | 1ba: ref-id is an array or pointer id. |
| 3a. ptr-id = register | |
| | 1bv: ref-id is a simple variable. |
| 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. |
| | |
---------------------------------------------------------------------------------------------
OWN Local Pointers.
Table 8-16. OWN Local Pointers
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
| own-local-pointer: | static-local-pointer: |
| | |
| OWN [type] POINTER ptr-decl [,...] ; | static [type] ptr-decl [,...] ; |
| | |
| | |
| ptr-decl: | ptr-decl: |
| | |
| ptr-id | * ptr-id |
| | |
---------------------------------------------------------------------------------------------
| | |
| Default type: LOGICAL | Default type: int (= long int) |
| | |
---------------------------------------------------------------------------------------------
| | |
| An OWN local pointer is allocated storage | Same as SPL, using a static local array. |
| global to the procedure, in the DB-relative | |
| area. It retains its values between | |
| successive calls to the procedure. | |
| | |
---------------------------------------------------------------------------------------------
| | |
| OWN pointers cannot be initialized. | static pointers may be initialized, using |
| | the syntax given for forms 1b and 1c in |
| | "POINTER Declaration". |
| | |
| | The pointer is initialized once, at the |
| | start of the program, not every time the |
| | function is called. |
| | |
---------------------------------------------------------------------------------------------
EXTERNAL Local Pointers.
Table 8-17. EXTERNAL Local Pointers
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
| external-local-pointer: | extern-local-pointer: |
| | |
| EXTERNAL type ptr-id [,...] ; | extern type ptr-id [,...] ; |
| | |
---------------------------------------------------------------------------------------------
| | |
| Default type: LOGICAL | Default type: int (= long int) |
| | |
---------------------------------------------------------------------------------------------
| | |
| An EXTERNAL local pointer refers to a | Similar to SPL. |
| global pointer that is declared GLOBAL in a | |
| separate compilation unit. The storage is | An extern local pointer refers to a global |
| allocated by the other unit. | pointer that is not declared static in a |
| | separate compilation unit. The storage is |
| | allocated by the other unit. See "Types of |
| | Declarations". |
| | |
---------------------------------------------------------------------------------------------
MPE/iX 5.0 Documentation