User manual

mikroPascal PRO for PIC32
MikroElektronika
231
Directives $DEFINE and $UNDEFINE
Use directive $DEFINE to dene a conditional compiler constant (“ag”). You can use any identier for a ag, with no
limitations. No conicts with program identiers 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 undene (“clear”) previously dened ag.
Note : Pascal does not support macros; directives $DEFINE and $UNDEFINE do not create/destroy macros. They only
provide ags for directive $IFDEF to check against.
Directives $IFDEF, $IFNDEF, $ELSE and $ENDIF
Conditional compilation is carried out by the $IFDEF and $IFNDEF directives. $IFDEF tests whether a ag is currently
dened, and $IFNDEF if the ag is not dened, 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}
<block of code>
{$ELSE}
<alternate block of code>
{$ENDIF}
First, $IFDEF checks if ag is dened by means of $DEFINE. If so, only <block of code> will be compiled.
Otherwise, <alternate block of code> 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.
Here is an example:
// Uncomment the appropriate ag for your application:
//{$DEFINE resolution10}
//{$DEFINE resolution12}
{$IFDEF resolution10}
// <code specic to 10-bit resolution>
{$ELSE}
{$IFDEF resolution12}
// <code specic to 12-bit resolution>
{$ELSE}
// <default code>
{$ENDIF}
{$ENDIF}