Comparison Syntax in Preprocessor Directives

See Also

The preprocessor supports three types of variables:

Most common comparisons (<=, <, >=, > and ==) are supported between the variables.

Boolean operations such as &&, ||, ! and ^ can also be performed on all symbol types.

Integers behave the same as strings when it comes to boolean operations. However, they are compared as true integers and can be used for such tasks as preprocessing code where various screen resolutions require different images that are optimized for different resolutions. For example, the directive

//#if ScreenWidth>100 && ScreenHeight>120

can specify a code block which will import images only for devices whose screens are larger than 100x120.

If a variable is defined, then it is considered a boolean with the value, "true." If the variable is not defined anywhere as an ability or configuration. then it is considered a boolean with value "false."

Comparisons should not be done on different variable types. However, such comparisons do not break the build process. If different variable types are compared, the preprocessor issues a warning in the Editor and Output windows, and evaluates the expressions as follows:

Operators

There are three types of operators with different priorities:

  1. The "not" operator (!)

    This operator has the highest priority and can be used on variables and expressions with the syntax !<identifier> or !<expression>.

    For example, //#if !(ScreenWidth>100 && ScreenHeight>120) checks if the screen size is smaller than 100x120.

    Since the ! operator has the highest priority, expressions such as //#if !ScreenSize=="100x200" are illegal and yield syntax errors because a boolean result cannot be compared to a string.

  2. Comparison operators

    Comparison operators have the second highest priority and perform typical comparison operations. Because the operators can compare strings lexically and integers mathematically, cross-type comparisons are supported. However, they can be used only in expressions and should compare two variables, not symbols.

    There is also a special comparison operator which performs a "subset" relationship operation. This operator is denoted by the character @. Both left and right arguments should be strings which represent two sets of tokens delimited by specific delimiters. The operator first considers both left and right string arguments as sets and then determines if the set from the left argument is a subset of the set from the right argument. The valid word delimiters are <whitespace>,',' and ';'. The delimiters can be mixed arbitralily within each argument, as shown in the following examples.

    "gif" @ "gif86, jpeg, gifaboo" = false

    "gif" @ "gif gif86 jpeg" = true

    "1 2 4;7,8" @ "0,1,2,3,4,5,6,7,8,9" = true

    "3 5 7 11 13" @ "0,1,2,3,4,5,6,7,8,9" = false

  3. Boolean operators

    Boolean operators have the lowest priority relative to the rest of the operators. They also have different priorities amongst each other, just as in the Java language. Boolean operators perform typical logical operations such as &&, || and ^ on boolean expression results, or check for variable definitions and then treat those as boolean expressions as well. Boolean operators are processed in the order:

    1. &&
    2. ^
    3. ||
See Also
About Project Configurations
About Abilities
About Preprocessing
Working with Project Configurations
Managing Preprocessor Blocks
About Preprocessor Directives

Legal Notices