Bit Switching - How?
David Goodenough
dg at lakart.UUCP
Sat Apr 15 00:43:12 AEST 1989
>From article <10007 at smoke.BRL.MIL>, by gwyn at smoke.BRL.MIL (Doug Gwyn ):
> In article <626 at gonzo.UUCP> daveb at gonzo.UUCP (Dave Brower) writes:
>>> x ^= z, y^= z; /* flip those that do */
> - x ^= z; /* flip those that do */
> - y^= z;
> -If you don't see _why_ this is the right way, you'd better not work on a
> -project with anyone but yourself.
>
> Hey, now, it's not all that clear cut. Conceptually the two
> assignments should occur in parallel; for some people using , to
> separate such assignments is the "natural" way to express that.
In either case, the assignments happen one after the other. As far as
I know, C has no equivalent to the BCPL mechanism:
a,b := b,a
Which is what we were trying to do in the first place :-) I would add
that the comma operator has it's place, and there is nothing wrong with
saying:
#define swap(a, b) ((a) ^= (b), (b) ^= (a), (a) ^= (b))
except the ususal caveats about lvalues and side effects. Think what
swap(i, getchar())
Would do :-) [Ouch]
--
dg at lakart.UUCP - David Goodenough +---+
IHS | +-+-+
....... !harvard!xait!lakart!dg +-+-+ |
AKA: dg%lakart.uucp at xait.xerox.com +---+
More information about the Comp.unix.questions
mailing list