Xref: utzoo comp.unix.questions:12945 comp.lang.c:17706 Path: utzoo!dptcdc!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!decvax!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.unix.questions,comp.lang.c Subject: Re: Bit Switching - How? Message-ID: <498@lakart.UUCP> Date: 14 Apr 89 14:43:12 GMT References: <10007@smoke.BRL.MIL> Organization: Lakart Corporation, Newton, MA Lines: 33 Folowup-To: comp.lang.c From article <10007@smoke.BRL.MIL>, by gwyn@smoke.BRL.MIL (Doug Gwyn ): > In article <626@gonzo.UUCP> daveb@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@lakart.UUCP - David Goodenough +---+ IHS | +-+-+ ....... !harvard!xait!lakart!dg +-+-+ | AKA: dg%lakart.uucp@xait.xerox.com +---+