GLBasic User Manual

Main sections

Preprocessor Commands

GLBasic comes with the following preprocessor commands. These commands affect how GLBasic compiles sections of code, rather than making choices whilst the program is running. This could, for example, cut down on a programs size, by having code for one platform not being included if a different platform is chosen to compile the program.

?DEFINE var



Define a preprocessor variable

?DEFINE ISWINDOWS


?ELSE



Used with ?IF, ?IFDEF and ?IFNDEF, this command allows an alternative section of code to be called if the original comparison fails

?ELSEIF expression


Is as an ?IF, but only if the ?ELSE block would be evaluated.

?IF ISWINDOWS > 2
?WARNING "Greater than 2"
?ELSE
?WARNING "Less or equal to 2"
?ENDIF


?ENDIF



Ends an ?IF, ?IFDEF and ?IFNDEF block

?IF ISWINDOWS > 2
?WARNING "Greater than 2"
?ENDIF


?ERROR



Generate an (error : preprocessor error) message followed by a user-defined message, and stop compiling

?ERROR "An error was found"


?IF expression


?IF DEFINED(name) OR DEFINED(name2)



Perform comparison with variables. You can also use mathematical expressions here. These operations are known:
+, -, *, /, AND, OR, ( ), DEFINED(name).
You can use symbols known through ?DEFINE earlier, here.

?IF WINDOWS > 4
?ENDIF


?IFDEF



Check to see if a variable has been defined

?IFDEF ISWINDOWS
?WARNING "ISWINDOWS defined"
?ENDIF


?IFNDEF



Check to see if a variable is not defined

?IFNDEF ISWINDOWS
?WARNING "ISWINDOWS not defined"
?ENDIF


?UNDEF



Undefine a previously define variable. It can be re-defined at any time later on

?UNDEF ISWINDOWS


?WARNING



Generate a (warning : preprocessor warning :) message, followed by user-defined text but continues compiling

?WARNING "This is a warning"


The following preprocessor variables are already defined by GLBasic :

Defined names


The following symbols are defined by the editor:
<B>GLB_DEBUG</B> Debug mode is active
<B>GLB_VERSION</B> The version number of the compiler
<B>GLB_CONSOLE</B> Program is a console program

Platforms:
<B>WIN32</B> Current platform is: Win32
<B>OSXUNI</B> Apple Mac OS-X
<B>LINUX</B> Linux x86
<B>IPHONE</B>iPhone, iPod Touch
<B>WINCE</B>Windows Mobile, Windows Phone, PocketPC
<B>GP2XWIZ</B>Gamepark Holding GP2X-Wiz
<B>WIN32DLL</B>Win32, DLL
<B>GP2X</B>Gamepark holding GP2X (F100, F200)
<B>XBOXLINUX</B>Linux x86, software renderer
<B>CAANOO</B>GPH Caanoo device

Example:
?IF GLB_VERSION < 7.0
?ERROR Precprocessor not enabled ;)
?ENDIF

?IF WIN32
?DEFINE FASTGFX
?ENDIF

?IF FASTGFX
STARTPOLY -1
POLYVECTOR 0, 0, 0,0, 0xffffff
POLYVECTOR 0,99, 0,0, 0xffffff
POLYVECTOR 99,99, 0,0, 0xffffff
ENDPOLY
?ELSE // slow graphics ->
DRRAWRECT 0,0,99,99, 0xffffff
?ENDIF


XBOXLINUX

See also...