The nonexistent operator (along = v. == lines)

Chris Dollin kers at hplb.hpl.hp.com
Sat Apr 6 00:11:31 AEST 1991


Dave Eisen writes (apropos of the ``xor'' discussion):

   #define XOR(a,b)	(!!(a) ^ !!(b))
   does what you want.

Hmm ... we can strip one of the !'s from each pair to get

    (!(a) ^ !(b))

If the XOR is likely to be used in conditional contexts (rather than value
contexts) then I'd guess that more compilers could optimise equality tests than
^ instructions (because more machines have some sort of branch-if-(n)eq), so
how about

#define XOR(a,b)   (!(a) != !(b))


--

Regards, Kers.      | "You're better off  not dreaming of  the things to come;
Caravan:            | Dreams  are always ending  far too soon."



More information about the Comp.lang.c mailing list