Top  Previous  Next


Conditional compilation directives intended for conditional compilation.




#IF condition


#ELSEIF condition








Conditional compilation is supported by the compiler.

What is conditional compilation?

Conditional compilation will only compile parts of your code that meet the criteria of the condition.


By default all your code is compiled.


Conditional compilation needs a constant to test.

So before a condition can be tested you need to define a constant.


CONST test 1


      Print "This will be compiled"


      Print "And this not"



notice Note that there is no THEN and that #ENDIF is not #END IF (no space)


You can nest the conditions and the use of #ELSE and #ELSEIF is optional.


There are a few internal constants that you can use. These are generated by the compiler:

_CHIP = 0

_RAMSIZE = 128


_SIM = 0

_XTAL = 4000000

_BUILD = 11162


_CHIP is an integer that specifies the chip, in this case the 2313

_RAMSIZE is the size of the SRAM

_ERAMSIZE is the size of the EEPROM

_SIM is set to 1 when the $SIM directive is used

_XTAL contains the value of the specified crystal

_BUILD is the build number of the compiler.


The build number can be used to write support for statements that are not available in a certain version :

#IF _BUILD >= 11162

   s = Log(1.1)


  Print "Sorry, implemented in"



Conditional compilation allows you to create different versions of your program but that you keep one source file.

For example you could make a multi lingual program like this :




'program goes here



  DATA "Hello"



  DATA "Guten tag"



By changing the just one constant you then have for example English or German data lines.


Conditional compilation does not work with the $REGFILE directive. If you put the $REGFILE inside a condition or not, the compiler will use the first $REGFILE it encounters. This will be changed in a future version.


A special check was added to to test for existence of constants or variables.

#IF varexist("S")

       ' the variable S was dimensioned so we can use it here


            ' when it was not dimmed and we do need it, we can do it here

    DIM S as BYTE




See Also

CONST , Edit Show Excluded Code