DEFINE Declaration and Reference [ SPL to HP C/XL Migration Guide ] MPE/iX 5.0 Documentation
SPL to HP C/XL Migration Guide
DEFINE Declaration and Reference
Table 4-8. DEFINE Declaration and Reference
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
| define-declaration: | define-directive: |
| | |
| DEFINE {define-id = text #} [,...] ; | #define define-id text |
| | |
---------------------------------------------------------------------------------------------
| | |
| All the characters after "=" and up to the | All the characters after define-id and up |
| next "#" outside a quoted string are | to the end of the last non-continued line |
| assigned to define-id. | are assigned to define-id. |
| | |
| The declaration may use more than one line. | The directive may use more than one line. |
| No continuation character is needed. | Lines are continued by the presence of "\" |
| | as the last nonblank character. |
| | |
| | The "#" character must be in column one. |
| | |
---------------------------------------------------------------------------------------------
| | |
| The declaration is referenced by using its | Same as SPL. |
| define-id anywhere in the subsequent source | |
| file. | |
| | |
---------------------------------------------------------------------------------------------
| | |
| The define-id is evaluated and compiled | Same as SPL. |
| where it is referenced, not in the | |
| declaration. | |
| | |
---------------------------------------------------------------------------------------------
| | |
| Example: | Example: |
| | |
| DEFINE NEXTC = CPTR:=CPTR+1#; | #define NEXTC ((*CPTR)++) |
| ... | ... |
| NEXTC; expands to: CPTR:=CPTR+1; | NEXTC; expands to: ((*CPTR)++); |
| | |
---------------------------------------------------------------------------------------------
In addition to the simple declaration allowed in SPL, HP C/XL also allows
macro directives with formal parameters. (See also "SWITCH Declaration"
above.) For example,
#define next(x) (*(x)++)
...
next(c); expands to: (*(c)++);
next(y); expands to: (*(y)++);
Please observe a couple of points:
* The left parenthesis,"(", in the HP C/XL directive and the reference
must be attached to the define-id (no spaces).
* The parameter substitution is literal. The formal parameter (x
above) is replaced by the actual parameters (the characters between
the parentheses) in the reference (c and y above).
* It is wise to enclose the formal parameters and the entire macro
directive in parentheses to ensure correct evaluation of the actual
parameters.
MPE/iX 5.0 Documentation