User manual
mikroBasic PRO for PIC32
MikroElektronika
233
Directives
Directives are words of special signicance which provide additional functionality regarding compilation and output.
The following directives are at your disposal:
- Compiler directives for conditional compilation,
- Linker directives for object distribution in memory.
Compiler Directives
Any line in source code with leading # is taken as a compiler directive. The initial # can be preceded or followed by
whitespace (excluding new lines). The compiler directives are not case sensitive.
You can use conditional compilation to select particular sections of code to compile while excluding other sections. All
compiler directives must be completed in the source le in which they begun.
Directives #DEFINE and #UNDEFINE
Use directive #DEFINE to dene a conditional compiler constant (“ag”). You can use any identier for a ag, with no
limitations. No conicts with program identiers are possible because the ags have a separate name space. Only one
ag can be set per directive.
For example:
#DEFINE extended_format
Use #UNDEFINE to undene (“clear”) previously dened ag.
Directives #IFDEF, #IFNDEF, #ELSE and #ENDIF
Conditional compilation is carried out by the #IFDEF and #IFNDEF directives. #IFDEF tests whether a ag is currently
dened, and #IFNDEF if the ag is not dened; i.e. whether a previous #DEFINE directive has been processed for that
ag and is still in force.
Directives #IFDEF and #IFNDEF are terminated with the #ENDIF directive and can have an optional #ELSE clause:
#IFDEF ag THEN
block of code
[ #ELSE
alternate block of code ]
#ENDIF
First, #IFDEF checks if ag is dened by means of #DEFINE. If so, only block of code will be compiled. Otherwise,
alternate block of code in #ELSE (if any) will be compiled. #ENDIF ends the conditional sequence. The result of the
preceding scenario is that only one section of code (possibly empty) is passed on for further processing. The processed
section can contain further conditional clauses, nested to any depth; each #IFDEF must be matched with a closing
#ENDIF.