#If
#If PreprocessorExpression
...
[ #Else If PreprocessorExpression
... ]
[ #Else
... ]
#Endif
#If ... #Endif预处理指令允许对代码进行条件编译。
PreprocessorExpression 是一个可以包含下列内容的基本布尔表达式:
-
一个预处理布尔常数(参看下面内容)。
-
一个预处理常数与字符串的比较(参看下面内容)。
-
Or 或 And 关键字。
-
成对括号包围的子表达式。
允许的预处理常数有:
常数
|
值
|
允许的比较操作
|
System
|
操作系统
|
= , <>
|
Architecture 或 Arch
|
CPU架构
|
= , <>
|
Version 或 Gambas
|
编译器版本
|
= , <> , < , <= , > , >=
|
Debug
|
调试信息是否可用
|
无
|
True
|
真
|
无
|
False
|
假
|
无
|
Examples
' 下面的代码在实际编译时,仅仅只编译一行'Print'语句
Public Sub Main()
#If System = "Linux"
#If Architecture = "x86_64"
Print "Linux 64 bits"
#Else
Print "Linux 32 bits"
#Endif
#Else If System = "FreeBSD"
Print "FreeBSD ?"
#Else
Print "Other !?"
#Endif
End