Visual J++ uses the #if, #elif, #else, and #endif conditional compilation directives to include and exclude portions of your source file, prior to compilation.
The #if directive is used to include a statement or block of statements when itÆs associated expression evaluates to true. An #if clause may also be used with an optional #elif clause and must have a closing #endif directive, or a compiler error occurs. If the expression defined by the #if statement is false, then the lines immediately following the directive (including the #if statement) are extracted from the source file, ending at the nearest #elif or #endif directive. If the expression following the #if directive evaluates to true, then the lines immediately following the directive are kept in the source file, and the lines following the optional #else clause are extracted from the source.
Any number of #elif directives can appear between the #if and #endif directives, but at most one #else directive is allowed. The #else directive, if present, must be the last directive before the #endif directive.
Example:
#if DEBUG
if (myArray.length( )
If all occurrences of constant-expression are false, or if no #elif directives appear, the preprocessor selects the text block after the #else clause. If the #else clause is omitted and all instances of constant-expression in the #if block are false, no text block is selected.
Syntax
#if <expression>
group of lines to be compiled
#elif <expression>
group of lines to be compiled
#else
group of lines to be compiled
#endif
Each #if directive in a file must have a closing #endif directive. And number of #elif directives can be included between the #if and #endif directives, but at most, one #else is allowed. The #else directive, if present, must be the last directive before #endif.
The #if, #elif, #else, and #endif directives can nest in the text portions of other #if directives. Each nested #else, #elif, or #endif directive belongs to the nearest preceding #if directive.
If an expression evaluates to true, Visual J++ processes the subsequent program source code and passes it to the compiler. If the text contains additional preprocessor directives, the preprocessor carries out those directives. Only text blocks selected by the preprocessor are compiled.
The preprocessor selects a single text item by evaluating the constant expression following each #if or #elif directive until it fins a true expression. It selects all text, including other preprocessor directives, up to its associated #elif, #else, or #$endif.
If all occurrences of expressions are false, or if no #elif directives appears, the preprocessor selects the text block after the #else clause. If the #else clause is omitted and all instances of constant-expression in the #if block are false, no text block is selected.