Home > lang > .if 
 en fr de es it nl pl pt pt_BR mk sq hu cs tr ar fa id vi ko ja ru zh zh_TW eo
Previous  Next  Edit  Rename  Undo  Search  Administration  
Documentation  
Warning! This page is not translated.  See english version 
#If
#If PreprocessorExpression
  ...
[ #Else If PreprocessorExpression
  ... ]
[ #Else
  ... ]
#Endif

The #If ... #Endif preprocessor directive allows to conditionnaly compile code.

PreprocessorExpression is a rudimentary boolean expression that can include the following:

The allowed preprocessor constants are:

Constant Value Comparison operators allowed
System The operating system. =, <>
Architecture or Arch The CPU architecture. =, <>
Version or Gambas The compiler version. =, <>, <, <=, >, >=
Debug If debugging information is enabled. None
True The True value. None
False The False value. None

Example

' Only one 'Print' line will be actually compiled by the following code

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

By using conditional compilation based on operating system or CPU architecture, you create an executable that will be specific to the operating system or CPU architecture used at compilation time.

This is usually not a good idea, so try as much as possible to detect operating system or CPU architecture at runtime, i.e. by testing the value of System.Family and System.Architecture in your code.