Conditional compilation directives intended for conditional compilation.
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"
Note that there is no THEN and that you need to use #ENDIF which has no space between END and IF , so #END IF is wrong!
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
_ERAMSIZE = 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 126.96.36.199"
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 "Guten tag"
By changing just one constant you can have for example English or German data lines.
Conditional compilation does work with the $REGFILE directive but you need to set the option 'Use New Method' in Environment IDE options.
A special check was added to 188.8.131.52 to test for existence of dimmed/defined constants or variables.
' 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
The Editor can show non included code with a different font color. This makes it more clear which code is included.