73
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
#define OPTION 0
'preprocessor directive
Const
COLOR=2
'constant used by your application
#
If
OPTION=COLOR
'to a confused programmer, this looks like 0=2, but COLOR
is not #defined, hence, it will be evaluated to 0
'hence, this code will be compiled in!
#endif
The #if directive also understands expressions, for example:
#define RED 0
#define GREEN 1
#define BLUE 2
...
#define OPTION 2
...
#
If
OPTION=GREEN+1
'will be compiled in, because GREEN=1, hence the entire expression
evaluates to 2, and OPTION=2
#endif
#ifdef - #else - #endif
#ifdef and #ifndef# are like #if, but instead of evaluating an expression they
simply checks if specified definition exists:
#ifdef OPTION
s="X"
'will be compiled if OPTION is defined
#
Else
s="1"
'will be compiled if OPTION is not defined
#endif
#ifndef is like #ifdef, but in reverse:
#ifndef OPTION
s="X"
'will be compiled if OPTION is not defined
#
Else
s="1"
'will be compiled if OPTION is defined
#endif
4.2.7.1
Scope of Preprocessor Directives
Each preprocessor directive applies only to its own
, not the
entire project. So, a #define directive in main.h will not be "visible" in main.tbs
unless the latter includes the main.h.
The only exception to the above are platform defines. These are globally visible
throughout your entire project. Platform defines determine options such as the
39