SPL to HP C/XL Migration Guide (30231-90001)

8- 20
||:|
|| |
| | #undef
function-id
|
|| |
| | 2. #define
function-id statement-process
|
|| |
||:|
|| |
| | #undef
function-id
|
|| |
---------------------------------------------------------------------------------------------
|| |
| A subroutine is like a procedure that has | No direct equivalent. |
| no option or local declaration sections. | |
|| |
---------------------------------------------------------------------------------------------
|| |
| Declared at the global level, it is | A static function is the closest global |
| available only to the main body of the | equivalent. It is available to all |
| compilation unit. It may access global | functions in the compilation unit. It may |
| identifiers. | access global identifiers. |
|| |
---------------------------------------------------------------------------------------------
|| |
| Declared at the local level, it is | The "best" local equivalent is a #define |
| available only to the procedure body where | macro directive, which will be expanded |
| it is declared. It may access global and | inline wherever it is called. See "DEFINE |
| local identifiers. | Declaration and Reference" for the #define |
| | syntax rules. Note that there is no |
| | control whatsoever over the data types of |
| | the macro's formal and actual parameters. |
|| |
| | The alternate solution is a static function |
| | at the global level. This can be awkward |
| | because the local procedure variables that |
| | were known to the subroutine are no longer |
| | automatically available. You could change |
| | the local variables to global, or pass them |
| | as parameters to the new function. |
|| |
---------------------------------------------------------------------------------------------
Table 8-27. SUBROUTINE Declaration Example
---------------------------------------------------------------------------------------------
| |||
| SPL Subroutine | HP C/XL Function | HP C/XL define Directive |
| |||
---------------------------------------------------------------------------------------------
| |||
| |||
| INTEGER SUBROUTINE A(B,C); | static short int A(B,C); | #define A(B,C) ( (B)+(C) )|
| VALUE B,C; | short int B,C; | ... |
| INTEGER B,C; | { | #undef A |
| A := B+C; | return B+C; | |
||}||
| |||
---------------------------------------------------------------------------------------------
| |
| This example shows the conversion of an SPL subroutine to an HP C/XL function and a |
| #define macro directive. |
| |
| In the #define directive version, the parentheses around B and C and the summation |
| are necessary to ensure correct evaluation of the parameters when the substitutions |
| for B and C are expressions. |
| |
---------------------------------------------------------------------------------------------
Careful examination of an SPL procedure may reveal that local variables
have been declared in the procedure for the sole purpose of providing
them to the subroutine. In that case, the variable declarations may
simply be moved to the new function.