ZBasic Language Reference
79
ZBasic Microcontrollers
The ZBasic compiler optionally supports the use of the conditional directives, as described in Section 3.9,
in project and argument files. Because conditionals are introduced with a # character and that same
character is recognized as a comment introduction character in project and argument files, support for
conditionals in these files is not enabled by default.
You may enable support for conditionals in project and argument files using the compiler option --
allow-conditionals. If this option appears as the first line in a project or argument file, conditionals
will be enabled for that file and for all subsequently processed project and argument files. If the --
allow-conditionals option appears on a line other than the first line, conditionals will be enabled for
subsequently processed files but not for the file in which the option appeared. Alternately, conditionals
may be enbled only for a specific project or argument file by placing the special comment #!allow-
conditionals as the first line of the file.
When creating conditionals in project and argument files, you may utilize symbols previously defined via
command line options as well as the built-in constant symbols described in Section 3.8.
3.15 Preprocessor Symbols
The ZBasic compiler supports several preprocessor symbols that can be used in your program code.
These are special sequences of characters that the compiler recognizes very early in the compilation
process. When they are recognized, they are replaced with a specific series of characters, different for
each symbol. Conceptually, the replacement process is very much like a global search and replace
operation in a text editor where context is not taken into account. The supported preprocessor symbols
are shown in the table below.
Symbol
Description
__DATE__
The month, day and year when compiled, e.g. Oct 21, 2005.
__TIME__
The hour, minute and second when compiled, e.g. 14:16:04.
__FILE__
The name of the file being compiled.
__LINE__
The line number of the file on which the symbol occurs.
Although these are primarily intended as an aid to the testing procedure for the compiler, they may be
useful in other circumstances. For example, you can cause the compilation date and time to be put in
Program Memory using the following instructions:
Private Const compDate as String = "__DATE__"
Private Const compTime as String = "__TIME__"
Private compData as StringVectorData({ compDate, compTime })
During the preprocessing, the symbols above will be replaced by their respective character values. Of
course, there will need to be some code that refers to compData, otherwise the compiler will optimize it
out.
One caveat is that, as mentioned earlier, the substitution is done without regard to context. This will be a
problem if you attempt to define a variable thus:
Dim a__LINE__b as Integer
If this happens to occur on line 23 of the file the compiler will see this as
Dim a23b as Integer
However, on a different line a reference to a__LINE__b will yield a different variable name, probably
causing the compiler to complain about use of an undefined variable. Since the preprocessor symbols
are case sensitive but ZBasic identifiers are not, the simple workaround is to spell the variable name
differently, e.g.
Dim a__line__b as Integer
|