Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!bionet!ames!amdahl!rtech!gonzo!daveb From: daveb@gonzo.UUCP (Dave Brower) Newsgroups: comp.unix.questions Subject: Re: Bit Switching - How? Summary: An example of bad coding practice Message-ID: <626@gonzo.UUCP> Date: 7 Apr 89 05:09:16 GMT References: <18944@adm.BRL.MIL> Reply-To: daveb@gonzo.UUCP (Dave Brower) Organization: Gonzo Media Group Lines: 28 In article <18944@adm.BRL.MIL> a unidentified co-conspirator says: > >void bit flip(x,y,mask) int *x, *y; /* mask can be more than one bit */ >{ > int z = (x ^ y) & mask; /* difference of interesting bits */ > if (z) /* some bits differ */ > x ^= z, y^= z; /* flip those that do */ >} I say, dear netters, that this use of the comma operator is an abomination, and we should fear for any freshmen who come upon it as an example of the sort of thing they ought to be writing. Rather: int z = (x ^ y) & mask; /* difference of interesting bits */ if (z) { /* some bits differ */ 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. -dB -- "I came here for an argument." "Oh. This is getting hit on the head" {sun,mtxinu,amdahl,hoptoad}!rtech!gonzo!daveb daveb@gonzo.uucp