You can use the #if statement to conditionally include or exclude selected lines of code from the compiled version of your program. This is useful if you need to maintain two or more slightly different versions of your program; #if allows you to maintain them both within the same source file.
If the condition following #if is evaluated as "true" or non-zero, then the statements in statementBlock1 are included in the compilation and the statements (if any) in statementBlock2 are ignored by the compiler. If the condition is evaluated as "false" or zero, then the statements in statementBlock1 are ignored by the compiler, and the statements (if any) in statementBlock2 are included in the compilation.
The #if statement must be matched by a following #endif statement.
condition must have one of the following forms:
constExpr is a "static integer expression." A static integer expression is a valid expression which consists only of:
In particular, it can't contain variables or function references. If you use this form of #if, then the condition will be evaluated as "true" if the expression's value is nonzero.
- integer literal constants
- previously-defined symbolic constant names
- operators (like +, -, *, /, >, ==, !=)
_symbolicConstant stands for a symbolic constant name.
_symbolicConstant is evaluated as "true" if the indicated constant was previously defined, regardless of its value.
_symbolicConstant is evaluated as "true" if the indicated constant was not previously defined.
Because #if can cause lines (including non-executable lines) to be completely ignored by the compiler, you can use it to control such things as the declaration of variables, program labels, constants, and even entire functions.
_myDebugStuff = 0 // 0 or 1
DebugPrint( a as
_dimensions = 3
( _dimensions == 3 )
Diag!( a, b, c ) = sqr
( a*a + b*b + c*c )
Diag!( a, b ) = sqr
( a*a + b*b )