
.int x = 5;
int nValue = Add(x, ++x);
With this code it depends on the compiler implementation whether 'Add' is called as 'Add( 5, 6 )' or 'Add( 6, 6 )'. Therefor one should always avoid to use ++ and  on a variable which occurs more than once within the expression ...
EXAMPLE 6 To illustrate the grouping behavior of expressions, in the following fragment
int a, b;
/* ... */
a = a + 32760 + b + 5;
the expression statement behaves exactly the same as
a = (((a + 32760) + b) + 5);
due to the associativity and precedence of these operators. Thus, the result of the sum (a + 32760) is
next added to b, and that result is then added to 5 which results in the value assigned to a. On a
machine in which overflows produce an explicit trap and in which the range of values representable by
an int is [32768, +32767], the implementation cannot rewrite this expression as
a = ((a + b) + 32765);
since if the values for a and b were, respectively, 32754 and 15, the sum a + b would produce a trap
while the original expression would not; nor can the expression be rewritten either as
a = ((a + 32765) + b);
or
a = (a + (b + 32765));
since the values for a and b might have been, respectively, 4 and 8 or 17 and 12. However, on a
machine in which overflow silently generates some value and where positive and negative overflows
cancel, the above expression statement can be rewritten by the implementation in any of the above
ways because the same result will occur.
By clicking you are agreeing to Experts Exchange's Terms of Use.
Title  # Comments  Views  Activity 

Issue accessing member variable of atomic class  16  99  
Fast access to array, using indexes, smart iterative search  2  84  
c++ substatte a varabe for a string in a LPCTSTR statment  8  67  
is twain_32.dll cmpatible with windows 10 ?  10  76 
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
10 Experts available now in Live!