The C standard does not specify the order in which the operands (suh as ++a) of an operator (such as the + in ++a + ++a) are evaluated and there is no guarantee when an affected variable will change its value.
consider
- int a=1,c=1,d;
-
int b=++a + ++a + ++a;
however, when are the ++a operands evaluated?
1. the ++a operands of (++a + ++a) evaluated and the result added then the final ++a evaluated and added? the result is a=4 and b=10
2. all the ++a operands evaluated and the then the + operations executed giving a=4 and b=12
running the above code Visual C++ gives b=12 and gcc gives b=10 (both give a=4)
the advice is do not use a variable more than once in an expression if one (or more) of the references has one of ++ or -- operators attached to it.