<=> and obfuscation

J. Shapiro jss at sjuvax.UUCP
Tue Feb 12 11:00:10 AEST 1985


[Aren't you hungry...]

b ^= a ^= b ^= a

> However, if a == b when you start out, you end up with a == 0 && b == 0.
>
> Arnold Robbins...

will work even if A = B. Suppose a = b = 1011 0100.

a = 1011 0100
b ^= a = 0000 0000
now b is 0000 0000
a ^= b ^= a = XOR of 1011 0100 and 0000 0000 == 1011 0100
now b is 0000 0000, and a is 1011 0100
b ^= a ^= b ^= a == 0000 0000 ^= 1011 0100 = 1011 0100

I believe that this works on *any* lvalues. If it doesn't work on your
system, make sure it isn't the system at fault.  I could see it not working
for arrays of different sizes.

	"There are a number of assignment operators... All require an lvalue as
their left operand." K&R p 191.

	And if you don't believe me, go read Rob Pike's paper on Multiwindow
bitmapped graphics.  It is how he says the bitmap swap should be
implemented, and I have *seen* it work with my own eyes.

Jon Shapiro
Haverford College



More information about the Comp.lang.c mailing list