Futurebasic/Language/Reference/compile long if
COMPILE LONG IF statement
editCOMPILE LONG IF
editStatement
edit✔ Appearance ✔ Standard ✔ Console
Syntax
editCOMPILE LONG IF condition
[statementBlock1]
[COMPILE XELSE
[statementBlock2]]
COMPILE END IF
Description
editYou can use the COMPILE LONG 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; COMPILE LONG IF
allows you to maintain them both within the same source file.
If the condition following COMPILE LONG 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.
condition
must be in one of the following forms:
constExpr
{DEF | NDEF} _symbolicConstant
TRON [= _false]
cpu68K
cpuPPC
carbonLib
- A list of any of the above separated by "
AND
" or "OR
". You may also optionally surround any valid sub-condition with parentheses.
constExpr
is a "static integer expression." A static integer expression is any valid expression which consists of only:
- integer literal constants;
- previously-defined symbolic constant names;
- operators (like +, -, *, /, >, =);
- parentheses
(In particular, it can't contain variables, nor function references.) If you use this form of COMPILE LONG IF
, then the condition will be evaluated as "true" if the expression's value is nonzero.
_symbolicConstant
stands for a symbolic constant name. DEF_symbolicConstant
is evaluated as "true" if the indicated constant was previously defined. NDEF_symbolicConstant
is evaluated as "true" if the indicated constant was not previously defined.
The condition TRON
is evaluated as "true" if debugging has been activated for the current section of code. The condition TRON = _false
is evaluated as "true" if debugging has not been activated for the current section of code. (See the <a href="tron.html">TRON</a>
statement for more details.)
If you use the keyword cpu68K
as the condition, it's evaluated as "true" if the current compilation is being compiled into Motorola 680x0 ("68k") machine code. If you use the keyword cpuPPC
as the condition, it's evaluated as "true" if the current compilation is being compiled into PowerPC machine code.
Example
editBecause COMPILE LONG 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. For example:
COMPILE LONG IF _needBigArray
DIM myArray&(3000)
COMPILE XELSE
DIM myArray&(30)
COMPILE END IF
COMPILE LONG IF _dimensions = 3
DEF FN Diagonal!(a!, b!, c!) = SQR(a!*a! + b!*b! + c!*c!)
COMPILE XELSE
DEF FN Diagonal!(a!, b!) = SQR(a!*a! + b!*b!)
COMPILE END IF
Note:
COMPILE LONG IF
blocks can be nested to a depth of 16 levels.