|
| Previous: 2.6.8 Conditional Expressions | TOC | Index | Back | Next: 2.6.10 Order of Evaluation |
Constant expressions are used wherever a value must be known at compile time. Only a limited set of operators is allowed in constant expressions and the order of evaluation is always from the left to the right. Only one single unary operator is allowed per factor. There are no precedence or associativity rules.
L+1*10
evaluates to (L+1)*10 and not to L+(1*10) like it would in ordinary expressions. The resons for this decision were
The following operators are recognized inside of constant expressions:
+ is frequently required to increase the
lengths of arrays. For example, if a buffer has to be used as a string, an
additional character must be appended to hold the delimiting NUL:
VAR buffer::BUFSIZE+1;
- has been added to avoid constructions like
CONST X = Y+%2;
which may now be written as
CONST X = Y-2;
* can be used to allocate memory for arrays of
structures, for example:
VAR Points[POINT * NUM_OF_POINTS];
| is useful when creating constant bit maps:
CONST A = 8, B = 16, AorB = A | B;
~ is also useful for creating constant bit maps:
CONST SignBit = 0x8000, ValueMask = ~SignBit;
The unary -, finally, can be used to negate
constants. This is particularly useful when counting down in FOR
loops where the step width must be constant:
FOR (i=99, -1, -STEPWIDTH) p();
| Previous: 2.6.8 Conditional Expressions | TOC | Index | Back | Next: 2.6.10 Order of Evaluation |