Except for the regular Turbo Pascal constructs for conditional compilation, the Free Pascal compiler also supports a stronger conditional compile mechanism: The f$IFg construct, which can be used to evaluate compile-time expressions.
The prototype of this construct is as follows:
{$if expr}
CompileTheseLines; {$else} BetterCompileTheseLines; {$endif} |
The content of an expression is restricted to what can be evaluated at compile-time:
The symbols are replaced with their value. For macros recursive substitution might occur.
The following boolean operators are available:
=, <>, >, <, >=, <=, AND, NOT, OR, IN
|
The IN operator tests for presence of a compile-time variable in a set.
The following functions are also available:
{$IF DEFINED(MySym)}
|
is equivalent to
{$IF DEFINED MySym}
|
In expressions, the following rules are used for evaluation:
If the complete expression evaluates to '0', then it is considered false and rejected. Otherwise it is considered true and accepted. This may have unexpected consequences:
{$if 0}
|
will evaluate to False and be rejected, while
{$if 00}
|
will evaluate to True.