Why no logical XOR operator

Cameron Simpson,Uhmmm..???? Who knows cameron at usage.csd.oz
Thu Sep 13 19:34:25 AEST 1990


>From article <1990Sep12.154515.18460 at druid.uucp>, by darcy at druid.uucp (D'Arcy J.M. Cain):
| Recently I had occasion to write something like the following code:
| 	if ((!x && (y & z)) || (x && !(y & z))
| 		something();
| Which would have been simpler as:
| 	if (x ^^ (y & z))
| 		something();
| If there was such a thing as a '^^' operator.  Does anyone know why C left
| out the logical XOR operator?

I can envisage two reasons:
	- It looks like && and ||, so it should short-circuit.
	  This doesn't make sense for XOR.
	- What's wrong with saying:
		!!x ^ !!y
	  which accomplishes exactly what you want.
	  I'm tempted to use the phrase "insufficient utility".

- Cameron Simpson
  cameron at spectrum.cs.unsw.oz.au



More information about the Comp.std.c mailing list