Obfuscated SWAP: not portable!
DAVID NEWALL
CCDN at levels.sait.edu.au
Mon Sep 4 20:53:41 AEST 1989
In article <149 at cpsolv.UUCP>, rhg at cpsolv.UUCP (Richard H. Gumpertz) writes:
> The exchange of x and y that has been under discussion:
> x ^= y ^= x ^= y
> is non-portable because it depends on right-to-left evaluation which is NOT
> specified in the C standard.
I think it is specified. (Perhaps it depends on whose standard you follow?)
K&R I, page 19:
"The line
nl = nw = nc = 0;
sets all three variables to zero. This is not a special case, but a
consequence of the fact that an assignment has a value and assignments
associate right to left."
David Newall Phone: +61 8 343 3160
Unix Systems Programmer Fax: +61 8 349 6939
Academic Computing Service E-mail: ccdn at levels.sait.oz.au
SA Institute of Technology Post: The Levels, South Australia, 5095
More information about the Comp.lang.c
mailing list