1.2.2. Conditionals

Felix provides the usual conditional directives #ifdef, #ifndef, #if, #elif, #else, #endif. [Add #switch/#case/#endswitch]

The #if and #elif directives require an argument.

The balance of the line is first tokenised by the standard Felix tokeniser and thus may contain Felix literals and Felix identifiers.

The line is then expanded by macro substitution. The result is then parsed as an expression and constant folded and must yield a boolean constant. Note that every name encountered must name a preprocessor macro.

Start felix section to tut/examples/mac103.flx[1 /1 ]
     1: #line 108 "./lpsrc/flx_tut_macro.pak"
     2: #import <flx.flxh>
     3: print "Defining FIRST"; endl;
     4: #define FIRST
     5: #ifdef FIRST
     6: print "detected FIRST"; endl;
     7: #else
     8: print "BAD"; endl;
     9: #endif
    10: 
End felix section to tut/examples/mac103.flx[1]
Start felix section to tut/examples/mac104.flx[1 /1 ]
     1: #line 118 "./lpsrc/flx_tut_macro.pak"
     2: #import <flx.flxh>
     3: #define FIRST 1
     4: #define SECOND 2
     5: #if FIRST == 1 and SECOND == 2
     6: print "OK"; endl;
     7: #else
     8: print "BAD"; endl;
     9: #endif
    10: 
End felix section to tut/examples/mac104.flx[1]
Start felix section to tut/examples/mac105.flx[1 /1 ]
     1: #line 128 "./lpsrc/flx_tut_macro.pak"
     2: #import <flx.flxh>
     3: #define FIRST 1
     4: #define SECOND 2
     5: #if if FIRST == 1 then SECOND == 2 else 1 == 0 endif
     6: print "OK"; endl;
     7: #else
     8: print "BAD"; endl;
     9: #endif
    10: 
End felix section to tut/examples/mac105.flx[1]
Start felix section to tut/examples/mac105a.flx[1 /1 ]
     1: #line 138 "./lpsrc/flx_tut_macro.pak"
     2: #define FIRST 1
     3: 
End felix section to tut/examples/mac105a.flx[1]
Start felix section to tut/examples/mac105b.flx[1 /1 ]
     1: #line 141 "./lpsrc/flx_tut_macro.pak"
     2: #import <flx.flxh>
     3: #import "mac105a.flx"
     4: #ifdef FIRST
     5: print "OK";
     6: #else
     7: print "BAD";
     8: #endif
     9: endl;
    10: 
End felix section to tut/examples/mac105b.flx[1]