Bit Switching - How?
Leo de Wit
leo at philmds.UUCP
Fri Apr 14 07:00:15 AEST 1989
In article <18944 at adm.BRL.MIL> rbj at dsys.icst.nbs.gov (Root Boy Jim) writes:
[]
|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 */
|}
What is this piece of code supposed to do? Since its return type is
'void', one would expect it to dereference its pointer arguments; it
doesn't (so in fact it is a pure function, and since it returns
nothing, a no-op 8-).
Well, probably the x, y in the function body should read *x, *y; and
what about renaming 'void bit flip' to 'void bitflip' ? Makes my
compiler happier. B.T.W. am I the first one to spot this?
Leo.
More information about the Comp.unix.questions
mailing list