Conditional Compilation
With conditional compilation, applicable blocks of code in a program can compile while other blocks are ignored. For example, you can compare different solutions to a problem, or you can make changes specially for a given culture. Conditional compilation statements operate only at compile-time, not at run-time.
You specify conditional compilation of a block of code with the statement Const If…Else
.
For example, you can make POSIX-compatible and Windows versions of the same program from the same source code.
You put code special to each platform between the lines that start Const If
, Else
, and End
.
Then you can use the compilation constants POSIX
and WINDOWS
to select the applicable code.
The example that follows shows how.
Const If POSIX Then
' Unix-like code goes here.
Else If WINDOWS Then
' Windows-only code goes here.
End If
Conditional compilation constants
Scope
How it is supplied | Scope |
---|---|
Command line | Global to all modules |
@Const directive |
Local to the module |
Platform constants
Constant | Platform |
---|---|
ANDROID | Google Android |
ARM_32 | 32-bit ARM processor |
ARM_64 | 64-bit ARM processor |
DESKTOP | Desktop operating system |
IOS | Apple iOS |
LINUX | Linux kernel |
MACOS | Apple Mac OS X |
MOBILE | Mobile operating system |
POSIX | POSIX-compliant operating system |
WINDOWS | Microsoft Windows |
X86_32 | 32-bit Intel x86-compatible processor |
X86_64 | 64-bit Intel x86-compatible processor |