|
| Previous: 2.6.1 Procedure Calls and Subscripts | TOC | Index | Back | Next: 2.6.3 Term Operators |
All unary operators have a high precedence and bind to single factors. Unless explicitly specified using parentheses, they never affect subexpressions containing other operators (except for postfix operators which have an even higher precedence). The suffix operators must bind stronger than the prefix operators, because this order leads to much more sensible semantics. For example
-P(a,b)
means `negate the result of applying P to a and b' and
~v[j]
means `evaluate to the inverse value of the j'th member of v'.
(If the order of precedence would be reverse, the meaning of the first example would be `apply whatever is at the negative address of P to a and b' and the second one would mean `evaluate to the j'th member of the vector located at the address expressed by the inverse value of v'.)
Altogether, there are four prefix operators. The minus sign (-) (which exists as a binary operator, too) evaluates to the negative value of its operand. Like in math expressions, any even number of minus signs has no effect. The unary minus sign is distinguished from the binary '-' by its context. If the sign occurs between two operands, it is binary. If it occurs at the place of a factor, it is unary and the factor itself follows.
The tilde operator (~) results in the value of its operand with all bits inverted. Since inverting a bit twice always yields the original state, even numbers of ~-operators have no effect, either.
The backslash (\) represents the logical NOT (while ~ represents the bitwise NOT). This operator evaluates to logical truth (-1), if its operand is logically false (0) and vice versa. Only the zero value represents logical falsity in T3X and all non-zero values represent logical truth. The normal form of the `true' value is -1. Two (or any other even number of) subsequent logical NOT operators may be used to create the normal form of a truth value.
The address operator (@) evaluates to the address of its operand. Therefore, it may only be applied to symbol names. The addresses of constants, structure member names, and classes may not be computed using @, because such entities have no addresses. Since the subscript operators bind stronger than the address operator, @ may be used to compute addresses of vector and structure members, and even the addresses of members of nested tables:
@v[i][j]
computes the address of the j'th member of the embedded vector v[i]. Of course, the address operator might be combined with byte subscipts, as well:
@s::i
yields the address of the i'th byte of s.
Annotation:
In early versions of T3X, it was a common technique to write
x := a+i;
to compute the address of the i'th member of a. Code like this is strongly deprecated, because it may cause undefined results. The only correct way to compute the address of the i'th member of the byte vector a is to write
x := @a::i;
For the same reason, code of the form
x := a + i*t.bpw();
cannot be assumed to work correctly and should be replaced with
x := @a[i];
| Previous: 2.6.1 Procedure Calls and Subscripts | TOC | Index | Back | Next: 2.6.3 Term Operators |