ZBasic Language Reference
77
ZBasic Microcontrollers
using a compiler option are visible in all modules while those defined in a particular module are only
visible in that module. Also note that conditional identifiers are essentially module-level constants. This
is true even if they are defined in a procedure. A consequence of this is that in spite of whether a
conditional identifier is defined inside a procedure or not, its value is visible to all subsequent conditional
expressions in the module.
A useful element of a conditonal expression is the function TargetHas(). This built-in function, what
takes a String parameter and available at compile-time only, returns True or False depending of the
availability for the current target of the ZBasic System Library routine named in the string.
Example
#if TargetHas("OpenPWM8")
Debug.Print "OpwnPWM8() is available."
#endif
BasicX Compatibility Note
Conditional constructs are not supported in BasicX compatibility mode.
3.10 Error Directive
Sometimes it is useful to be able to purposely generate an error message in order to remind yourself of
some detail or condition that requires attention. Often, this is used in conjunction with conditional
directives to point out that an incompatible set of conditions exists.
The form of the error directive is shown below.
#error <message>
All of the characters beginning with the first non-white space character following #error up to the end-of-
line will appear as the error message. If the last character on the line is an underscore and is preceded
by a space or tab character, it is treated as a continued line and all of the characters on the next line up to
the end-of-line will also be part of the error message.
Example
#if PLATFORM = "alpha"
Const Frequency As Single = 42.347
#elseif PLATFORM = "beta"
Const Frequency As Single = 45.347
#else
#error No platform specified.
#endif
3.11 Notice Directive
This directive is similar to the #error directive discussed in the previous section in that it adds a string to
the error output (unless disabled by the option --notice=off or the directive Option Notice Off).
However, its use does not increase the error count like #error does.
The form of the error directive is shown below.
#notice <message>
|