SPL to HP C/XL Migration Guide (30231-90001)
10- 3
The
HP C/XL Reference Manual Supplement
describes the compiler options
and #pragma directives listed above, as well as others not available to
SPL.
--------------------
1 Where an SPL $CONTROL compiler command is replaced by an HP C/XL
compiler option, please be aware that the compiler option applies to
all of the source being compiled at the same time. These compiler
options are convenient because the source remains unmodified, but you
do lose the line-by-line toggling of the SPL compiler command.
$IF Command (Conditional Compilation)
Table 10-3. $IF Command
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
|
if-command
: |
if-directive
: |
| | |
| $IF [X
n
={OFF | #if
constant-expression
|
| ON}] | |
| | ... |
| | |
| | [#else |
| | ...] |
| | |
| | #endif |
| | |
---------------------------------------------------------------------------------------------
| | |
| SPL predefines ten switches named | The SPL switches may be emulated by |
| X0,...,X9, whose initial values are OFF. | defining them equal to zero in #define |
| The switches may be changed with the $SET | directives. |
| command (see below) and tested with the $IF | |
| command. | #define OFF 0 |
| | #define ON 1 |
| | #define X0 OFF |
| | ... |
| | |
---------------------------------------------------------------------------------------------
| | |
| When a $IF command is executed, and the | When an #if directive is executed, and the |
| switch test is true (or the test is | expression is true (nonzero), then all the |
| omitted), then all the following source | following source lines are compiled, down |
| lines are compiled, down to the next $IF | to the next #else or #endif directive. If |
| command. If the test is false, the same | the test is false (zero), the same source |
| source lines are skipped. | lines are skipped. |
| | |
| Note that there is no form of "else" except | The #else directive marks the start of a |
| a $IF with the opposite test. A $IF with | block of lines that are compiled only if |
| no parameter serves to end the conditional | the test is false. They are skipped if the |
| block. | test is true. The #else block is |
| | terminated by an #endif directive. |
| | |
---------------------------------------------------------------------------------------------
| | |
| For example, X3 is used to control a choice | Assuming appropriate initialization, as |
| between two DEFINE declarations: | above, the corresponding example in HP C/XL |
| | could be coded as: |
| $IF X3 = ON | |
| DEFINE GLOBALVAL = 99#; | #if X3 == ON |
| $IF X3 = OFF | #define GLOBALVAL 99 |
| DEFINE GLOBALVAL = 101#; | #else |
| $IF | #define GLOBALVAL 101 |