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 C++ section to tut/examples/mac103.flx[1 /1 ]
     1: include "std";
     2: print "Defining FIRST"; endl;
     3: #define FIRST
     4: #ifdef FIRST
     5: print "detected FIRST"; endl;
     6: #else
     7: print "BAD"; endl;
     8: #endif
     9: 
End C++ section to tut/examples/mac103.flx[1]
Start C++ section to tut/examples/mac104.flx[1 /1 ]
     1: include "std";
     2: #define FIRST 1
     3: #define SECOND 2
     4: #if FIRST == 1 and SECOND == 2
     5: print "OK"; endl;
     6: #else
     7: print "BAD"; endl;
     8: #endif
     9: 
End C++ section to tut/examples/mac104.flx[1]
Start C++ section to tut/examples/mac105.flx[1 /1 ]
     1: include "std";
     2: #define FIRST 1
     3: #define SECOND 2
     4: #if if FIRST == 1 then SECOND == 2 else 1 == 0 endif
     5: print "OK"; endl;
     6: #else
     7: print "BAD"; endl;
     8: #endif
     9: 
End C++ section to tut/examples/mac105.flx[1]
Start C++ section to tut/examples/mac105a.flx[1 /1 ]
     1: #define FIRST 1
     2: 
End C++ section to tut/examples/mac105a.flx[1]
Start C++ section to tut/examples/mac105b.flx[1 /1 ]
     1: include "std";
     2: #import "mac105a.flx"
     3: #ifdef FIRST
     4: print "OK";
     5: #else
     6: print "BAD";
     7: #endif
     8: endl;
     9: 
End C++ section to tut/examples/mac105b.flx[1]