Re: seemingly inconsistent behaviour of ^= with int *

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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).
> 
> However, if I access a and b through pointers, it breaks.
> 
> int *p;
> int *q;
> 
> p = &a;
> q = &b;
> 
> *p ^= *q ^= *p ^= *q;

I'd recommend you add -Wsequence-point to your command line options ;-)

Johann


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux