Qore Programming Language Reference Manual  1.12.2
Conditional Parsing and Parse Defines

Qore supports conditional parsing with parse defines similar to the C/C++ preprocessor. In the current version of Qore, the implementation is very simple; only the following parse directives are supported: %define, %else, %endif, %ifdef, and %ifndef.

Basically, the above allow for the existence (or lack thereof) of a parse define to affect which code is parsed into the program at parse time.

Parse defines are defined on the command-line (or through the C++ API when executed in embedded code), as well as created automatically based on sytem options (see Qore::Option for a list of option constants that are also defined as parse defines); all library options (if the option is True, then it is defined as True, if the option is False, then it is not defined at all).

Note that "Unix" is defined on all Unix platforms (also on Cygwin), while "Windows" is defined on native Windows ports (but not on Cygwin, as this is treated as Unix when compiling, as all Unix features are available).

Additionally, the following options are defined in every program (however they are not yet useful when parsing as the value of parse options cannot be used yet at parse time; only the existence or lack thereof can affect parsing in this version of Qore when parsing at least).

Qore Parse Defines

Define Value
QoreVersionString Version string for the Qore library
QoreVersionMajor Major version for the Qore library
QoreVersionMinor Minor version for the Qore library
QoreVersionSub Sub version for the Qore library
QoreVersionBuild Build version for the Qore library
QoreVersionBits 32 or 64 depending on the library target
QorePlatformCPU The CPU targeted by the library
QorePlatformOS The OS targeted by the library

Additionally, only if the Qore library was compiled with debugging support, the following parse define is present (otherwise it is not defined):

Qore Optional Parse Defines

Define Value
QoreDebug True
See also
Qore::Option for a list of option constants that are also defined as parse defines

Here is an example of using parse defines in a program:

%ifndef HAVE_TERMIOS
printf("This program requires UNIX TermIOS features to be present; it does not run on platforms without this feature (current platform: %s); exiting...\n", Qore::PlatformOS);
exit(1);
%endif
string printf(string fmt,...)
Outputs the string passed to standard output, using the first argument as a format string; does not e...

Furthermore, parse defines can be manipulated in embedded code using the following functions: