$IF, $IFNDEF, $ELSE, $ELSEIF and $ENDIF directives

Purpose: To provide conditional compilation.

Note well: Any conditional directives, in a program without an explicit main function, will be local to the main function UNLESS the conditional directives are placed AFTER a FUNCTION or SUB.

Conditional directives can not encase a SUB or FUNCTION procedure or an INCLUDE directive.

If you want GLOBAL preprocessor conditionals, placed at the top of the module level code, executing before anything else then build the program using a $NOMAIN directive and an explicit main function.

These five directives allow you to compile special versions of your final program based on your certain conditions.

This BCX code


 CONST FooBar

 $IFNDEF FooBar
   CONST A = 1
 $ELSE
   CONST A = 2
 $ENDIF

 ? A

tranlates to the following C code


 // ***************************************
 //            User Defined Constants
 // ***************************************
 
 #define FooBar
 
 // ***************************************
 //                  Main Program
 // ***************************************
 
 int  main(int argc, char *argv[])
 {
 #ifndef FooBar
 #define A 1
 #else
 #define A 2
 #endif
 printf("% d\n",(int)A);
 return 0; //  End of main program

Example:

As an example, suppose you wanted all the messages in your program to be in a particular language, you could use something like the following sample. There would only be ONE set of language statements in the final .EXE


 '*******************************************************************
 ' Conditional compilation using:  $IF/$ELSE/$ELSEIF/$ENDIF directives
 '*******************************************************************
 '  By uncommenting one of the following CONST statements, the resulting
 '  executable code changes as well.  Only the code that is associated
 '  with the true condition is compiled, the rest is disregarded.
 '*******************************************************************
 
 'CONST ENGLISH
 'CONST SPANISH
 'CONST GERMAN
 
 $IF ENGLISH
  PRINT "Good Day"
  PRINT "What's happening?"
 $ELSEIF SPANISH
  PRINT "Buenas Dias"
  PRINT "Como va?"
 $ELSEIF GERMAN
  PRINT "Guten Tag"
  PRINT "Was ist los?"
 $ELSE
  PRINT "Greetings Earthling"
  PRINT "Where is the cafeteria?"
 $ENDIF