$IFDEF and $IFNDEF Compiler Directives |
|
|
The $IFDEF directive provides conditional compilation.
Format
$IFDEF name ...statements... $ELSE ...statements... $ENDIF
The $ELSE and associated statements are optional. Statements conditioned by the $IFDEF directive are ignored if name has not been defined by a previous $DEFINE directive. Statements under the $ELSE directive are ignored if name has been defined by a previous $DEFINE directive.
The $IFNDEF directive provides the inverse action of $IFDEF, compiling the following statements if name has not been defined.
Multiple token names may specified in a single directive with an intervening AND or OR operator (or their symbolic equivalents, & and !). The expression is evaluated left to right and brackets are not permitted.
$IFDEF and $IFNDEF statements may be nested to any depth though nesting more than two deep can make program maintenance very difficult.
Portable Software
One use of conditional compilation is to allow a single source stream to be compiled in different multivalue environments rather than having to maintain separate source streams. When compiling on QM, the name QM is always defined thus a construct such as $IFDEF QM SETLEFT 'DATE' FROM INV.F LOOP SELECTRIGHT 'DATE' FROM INV.F SETTING DT UNTIL STATUS() READLIST IDS THEN GOSUB PROCESS REPEAT $ENDIF might be used scan an alternate key index on QM. The same program might contain an equivalent for UniVerse $IFDEF UV BSCAN DT, IDS FROM INV.F USING 'DATE' RESET THEN LOOP GOSUB PROCESS BSCAN DT, IDS FROM INV.F USING 'DATE' ELSE EXIT REPEAT END $ENDIF though UniVerse does not define the UV token automatically. This would need to be done in the source code, probably as part of a platform specific include record.
Some environments such as D3 do not support conditional compilation. There is a skeleton pre-processor program in the BP file of the QMSYS account that can be compiled on D3, etc to resolve conditional compilation constructs.
See also: |