64 Expressions
The xcpp preprocessor allows for evaluation of expressions in a similar manner to the C/C++ compiler.
The following table shows the operators and their precedence (highest precedence at the top of the table):
| Operator | Description |
|---|---|
! |
Logical negation Bitwise negation Unary minus Unary plus |
^^
|
Power |
* |
Multiplication Division Modulus |
+ |
Addition Subtraction |
<< |
Bitwise shift left Bitwise shift right |
< |
Comparison less-than Comparison less-than-or-equal-to Comparison greater-than Comparison greater-than-or-equal-to |
== |
Comparison equal-to Comparison not-equal-to |
&
|
Bitwise AND |
^
|
Bitwise XOR |
|
|
Bitwise OR |
&&
|
Logical AND |
||
|
Logical OR |
? :
|
Ternary conditional (if-then-else) |
Expressions are evaluated in the following circumstances:
- Assignment to a variable in the @let directive;
- Initialising a typed formal argument when invoking a macro;
- Calculating the return value when invoking a macro that has a typed return value;
- The @() directive; and
- Evaluation of the boolean expression in @if directives.
The supported types are bool, int, double, char and string.
Unlike C/C++ there is no implicit conversion from int to bool.
Special functions
The trigonometric functions sin, cos and tan are available. Also
the exponential exp, and natural logarithm log (base e).
| Before translation | After translation |
|---|---|
| |