Limited dependence should be placed on C++ operator precedence rules in expressions
Limited dependence should be placed on C++ operator precedence rules in expressions.
Use parentheses to clearly indicate the order of evaluation.
Depending on operator precedence can cause the following issues:
If you or another code reviewer reviews the code, the intended order of evaluation is not immediately clear.
It is possible that the result of the evaluation does not meet your expectations. For instance:
In the operation *p++, it is possible
that you expect the dereferenced value to be incremented.
However, the pointer p is incremented
before the dereference.
In the operation (x == y | z), it is
possible that you expect x to be compared
with y | z. However, the
== operation happens before the
| operation.
If you expect a rule violation but do not see it, refer to the documentation for Polyspace® Code Prover™ or Polyspace Code Prover Server™.
| Group: Expressions |
| Category: Advisory |