On Tue, 19 Apr 2005 17:12:50 +0530, "Binand Sethumadhavan"
<binand@xxxxxxxxx> wrote:
On 4/19/05, Sridharan Anand^^^^^^^^^
<sanand@xxxxxxxxxx> wrote:
a ^= b ^= a ^= b;
I hate to be such a pedant, but this causes undefined behaviour due to
the absence of a sequence point between successive assignments. In
other words, the expression contains multiple ambiguous side effects. I
forget
Spot on. Even its expanded (and compliant) version:
a ^= b; b ^= a; a ^= b;
will grok if you call it as swap(v,v).
The best way of doing it is:
tmp = a;
a = b;
b = tmp;
and the rest are only of academic interest and should not really be in
robust programs.