seemingly inconsistent behaviour of ^= with int *

Andrew Haley aph@redhat.com
Thu Dec 8 15:48:00 GMT 2011


On 12/08/2011 03:32 PM, Paul LaFollette wrote:
> Kind people,
> I am befuddled, and looking for understanding:
> 
> int a, b;
> a = 7;
> b = 12;
> 
> a ^= b;
> b ^= a;
> a ^= b;
> 
> should swap the contents of a and b (and it does).
> Since ^= associates to the right
> 
> a ^= b ^= a ^= b;
> 
> should do the same thing (and it does).

No, because you're modifying an object more than once between sequence
points.

More at http://c-faq.com/expr/seqpoints.html

Andrew.



More information about the Gcc-help mailing list