ZBasic Language Reference
77
ZX Microcontroller Family
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 thusly:
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
3.16 Array Data Order
RAM-based arrays are stored sequentially in memory with the first index varying the fastest and the last
index varying the slowest. Consider a two-dimensional array defined as:
Dim ba(1 To 3, 1 To 2) as Byte
The bytes of this array are assigned addresses in memory sequentially as:
ba(1,1) ba(2,1) ba(3,1) ba(1,2) ba(2,2) ba(3,2)
Whether this constitutes row-major order or column-major depends on whether you consider the first
index of a two-dimensional array to be the column and the second index the row or vice versa. To a large
extent, this is a non-issue as long as you remember that the first index varies the fastest.