Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
Compiler Directives
mikroPascal PRO for AVR treats comments beginning with a 
“$”
immediately fol-
lowing an opening brace as a compiler directive; for example, 
{$ELSE}
. The compil-
er directives are not case sensitive.
You can use a conditional compilation to select particular sections of code to com-
pile, while excluding other sections. All compiler directives must be completed in the
source file in which they have begun.
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.
Note: Pascal does not support macros; directives 
$DEFINE
and 
$UNDEFINE
do not cre-
ate/destroy macros. They only provide flags for directive 
$IFDEF
to check against.
Directives $IFDEF..$ELSE
Conditional compilation is carried out by the 
$IFDEF
directive. 
$IFDEF
tests whether
a flag is currently defined or not, i.e. whether a previous 
$DEFINE
directive has been
processed for that flag and is still in force.
Directive 
$IFDEF
is terminated with the 
$ENDIF
directive, and can have an optional
$ELSE
clause:
{$IFDEF flag}
<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>
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.
177
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroPASCAL PRO for AVR
CHAPTER 5