Navigation bar
  Start Previous page
 81 of 206 
Next page End  

ZBasic Language Reference
73
ZX Microcontroller Family
With regard to the built-in constants referring to the version number, consider the version number v1.2.3. 
In this version number, the major value is 1, the minor value is 2 and the variant is 3.
Additionally, for each target device there exists a set of built-in pin name constants of the form
<port>.<bit> where <port> is a letter (case insignificant) referring to an I/O port and <bit> is a
digit in the range 0-7 referring to a bit of the port.  The value of the pin name is of type Byte and it may
be the pin number for the target device corresponding to that port bit or it may be an encoded port/pin
designator (as controlled by Option PortPinEncoding).  For example, when the target device is
ZX24, the pin name C.7 has the value 5 if Option PortPinEncoding is off.
3.10 Conditional Compilation Directives
The ZBasic compiler supports conditional compilation.  This means that you can add conditional
constructs to your code to specify that a portion of the code should be or should not be processed by the
compiler.  This is useful in order to create source code that can be compiled in different ways.  Such
flexibility can be used to create special versions of your application for different markets or for different
customers, etc.  It also provides a fast way to logically remove blocks of code from your program while
leaving the source code intact so that it can be easily restored.
A key element of conditional compilation is the ability to define special identifiers and to give them values. 
These identifiers can then be used in conditional expressions that control whether or not a block of code
will be processed normally by the compiler or ignored completely.  The compiler supports the definition of
conditional identifiers on the command line but you can also define them in your source code as well
using the following syntax:
#define <identifier> [ [=] <expression> ]
Here, <identifier>  is the name of the conditional identifier that you want to define.  You may also
give it a value, represented by <expression>, which may be an integral or string type.  If you do not
specify a value, a default value of 1 is used.  The expression may include literals or identifiers previously
Examples
#define EXPERIMENTAL
#define Version 23
#define Greeting = "Hello"
If you attempt to define a conditional identifier that is already defined, you will get an error message to
that effect.  If you want to redefine a conditional identifier you must first “undefine” the existing one using
the directive:
#undef <identifier>
If the specified identifier is not actually defined, no error message will be issued so you may freely use
this directive to ensure that no definition exists prior to defining a conditional identifier.  Note that
undefining an identifier that was defined on the command line only has effect in the current module.  All
other modules will see the original value.
Once you have defined your conditional identifiers, you may use them in conditional directives that are
similar to If statements.  The first two forms presented below are complementary.
#ifdef <identifier>
<other-text>
#endif
#ifndef <identifier>
<other-text>
#endif
Previous page Top Next page