pu*********@hotmail.com wrote in message news:<c7**************************@posting.google. com>...
Richard Herring <ju**@[127.0.0.1]> wrote in message news:<1m**************@baesystems.com>... In message <97**************************@posting.google.com >, Steve
<ng*****@my-deja.com> writesThe xor solution was really elegant. I would not have thought about it
and never knew it could be done this way.
X XOR Y XOR Y = X (assign in y variable, cancel out both Y)
X XOR Y XOR X = Y (assign in x variable, cancel out both X)
And it DOESN'T WORK (no apologies for shouting) if X and Y are both
references to the same object. Don't do it!
Well... You *could* add a self-assignment guard.
Sometimes coders find themselves working on extremely limited hardware.
Like a smoke detector or something. And every variable is taking up
the very limited RAM that was only allowed by having an arm-wrestling
match with the comptroller and the accountant.
Downthread discussion makes it clear that I didn't make myself clear.
Code can go in ROM. ROM may be cheaper than RAM. (Lots of reasons
from power supply to temperature sensitivity etc. And it takes a
specialist compiler to accomplish.) A temp can't go in ROM.
Still, in situations where your RAM is *that* limited, probably
you code in assembler, and the discussion is moot.
Socks