Mikroelektronika MIKROE-724 データシート
![Mikroelektronika](https://files.manualsbrain.com/attachments/e0529b3b58069a916ad7bb89f7e9f5f0eda73421/common/fit/150/50/1b07b99aa3112e022a916b06db07f1f4f211e91d41878452d87c7638b1bf/brand_logo.gif)
236
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
Directives #DEFINE and #UNDEFINE
Use directive
#DEFINE
to define a conditional compiler constant (“flag”). You can use any identifier for a flag, with no
limitations. No conflicts with program identifiers are possible because the flags have a separate name space. Only one
flag can be set per directive.
For example:
#DEFINE extended_format
Use
#UNDEFINE
to undefine (“clear”) previously defined flag.
Directives #IFDEF, #IFNDEF, #ELSE and #ENDIF
Conditional compilation is carried out by the
#IFDEF
and
#IFNDEF
directives.
#IFDEF
tests whether a flag is currently
defined, and
#IFNDEF
if the flag is not defined; i.e. whether a previous
#DEFINE
directive has been processed for that
flag and is still in force.
Directives
#IFDEF
and
#IFNDEF
are terminated with the
#ENDIF
directive and can have an optional
#ELSE
clause:
#IFDEF flag THEN
block of code
[ #ELSE
alternate block of code ]
#ENDIF
First,
#IFDEF
checks if
flag
is defined 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
.
Here is an example:
‘ Uncomment the appropriate flag for your application:
‘#DEFINE resolution10
‘#DEFINE resolution12
#IFDEF resolution10 THEN
// <code specific to 10-bit resolution>
#ELSE
#IFDEF resolution12 THEN
// <code specific to 12-bit resolution>
#ELSE
// <default code>
#ENDIF
#ENDIF
Unlike
#IFDEF, #IFNDEF
checks if
flag
is not defined by means of
#DEFINE
, thus producing the opposite results.