Portable XOR
Joseph Beckenbach {Adapter Software Release Engr}
jerbil at ultra.com
Sat Apr 20 02:25:26 AEST 1991
Following up my own article here, and apologies for missed names:
> In <157 at revcan.UUCP> darren at revcan.UUCP (Darren Morbey) writes,
>asking for a macro returning XOR of its arguments, evaluating once and
>only once. I've not worked out a more elegant solution for my toolbag,
... but I've had a light flurry of mail with comments, including
one from the Netherlands pointing out that XOR(a,XOR(b,c)) would fail using
my implementation. Serves me right for reusing old code without doing a
double-check of other things! :-)
Another sent me the macro
#define XOR(o,_) ((o)?!(_):(_))
which "does the right thing". Another macro for toolbox.h :-)
Joseph Beckenbach
journeyman programmer
(still working towards craftsman status)
--
Joseph Beckenbach jerbil at ultra.com VEGGIES FOREVER!
work 408-922-0100 x246
More information about the Comp.lang.c
mailing list