A
Asbjørn Sæbø
Lint gives me warning about a code fragment, saying that the result is
dependent upon order of evaluation. I fail to see that it can be so.
The code fragment below illustrates the situation:
-------------------
#define CONSTANT SOME_VALUE
uint16_t my_var = <another_value>;
my_var = ++my_var % CONSTANT;
----------------------
How can the order of evaluation affect the result of this calculation?
My reasoning is that the increment operator has higher presedence than
the modulo operator, and should therefore be applied to my_var before
the modulo operator is applied to my_var, regardless of which side of
the modulo operator is evaluated first. Therefore, order of
evaluation should not influence the result?
Am I correct? And if not, how and why?
Asbjørn Sæbø
dependent upon order of evaluation. I fail to see that it can be so.
The code fragment below illustrates the situation:
-------------------
#define CONSTANT SOME_VALUE
uint16_t my_var = <another_value>;
my_var = ++my_var % CONSTANT;
----------------------
How can the order of evaluation affect the result of this calculation?
My reasoning is that the increment operator has higher presedence than
the modulo operator, and should therefore be applied to my_var before
the modulo operator is applied to my_var, regardless of which side of
the modulo operator is evaluated first. Therefore, order of
evaluation should not influence the result?
Am I correct? And if not, how and why?
Asbjørn Sæbø