Re: swap two integers without using a tmp variable?
puppet_sock_at_hotmail.com
Date: 06/22/04
- Next message: Julie: "Re: STL NewbieQ: Remove entry from multimap and keep scanning"
- Previous message: Phlip: "Re: I've painted myself into a corner!"
- In reply to: Richard Herring: "Re: swap two integers without using a tmp variable?"
- Next in thread: Howard: "Re: swap two integers without using a tmp variable?"
- Reply: Howard: "Re: swap two integers without using a tmp variable?"
- Reply: Walter Tross: "Re: swap two integers without using a tmp variable?"
- Reply: Risto Lankinen: "Re: swap two integers without using a tmp variable?"
- Reply: puppet_sock_at_hotmail.com: "Re: swap two integers without using a tmp variable?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 22 Jun 2004 14:48:38 -0700
Richard Herring <junk@[127.0.0.1]> wrote in message news:<1myFlguI4C2AFwv2@baesystems.com>...
> In message <976e0586.0406220444.4ed62241@posting.google.com>, Steve
> <ngsteve@my-deja.com> writes
> >The 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.
Socks
- Next message: Julie: "Re: STL NewbieQ: Remove entry from multimap and keep scanning"
- Previous message: Phlip: "Re: I've painted myself into a corner!"
- In reply to: Richard Herring: "Re: swap two integers without using a tmp variable?"
- Next in thread: Howard: "Re: swap two integers without using a tmp variable?"
- Reply: Howard: "Re: swap two integers without using a tmp variable?"
- Reply: Walter Tross: "Re: swap two integers without using a tmp variable?"
- Reply: Risto Lankinen: "Re: swap two integers without using a tmp variable?"
- Reply: puppet_sock_at_hotmail.com: "Re: swap two integers without using a tmp variable?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|