Obfuscated SWAP: not portable!
Richard H. Gumpertz
rhg at cpsolv.UUCP
Sat Sep 9 01:47:31 AEST 1989
"x ^= y ^= x ^= y" differs from "x = y = z = 0" in that the former makes TWO
assignments to x. Side effects (i.e., assignments to variables) need only be
completed at "sequence points"; between sequence points, any order of
evaluation (including assignment operators) is allowed!
The following are all legal interpretations of the sequence in question,
yet may yield different results:
(t = x ^= y, x ^= y ^= t)
(t = x, y ^= x ^= y, x = t ^ y)
(t = x ^ y, x ^= y ^= t, x = t)
I am sure there are other interpretations as well.
More information about the Comp.lang.c
mailing list