the logical xor operator!

T. William Wells bill at proxftl.UUCP
Sun Jul 3 12:08:27 AEST 1988


In article <1310 at ark.cs.vu.nl>, maart at cs.vu.nl (Maarten Litmaath) writes:
> Hello, it's me again.
> This time the question is: why hasn't C got a logical xor operator?
>
>       logical and: &&
>       logical or:  ||
>       logical xor: ^^         <- fits nicely!
>
> Of course the way to come around the deficiency is:
>
>       if (!(expr1) != !(expr2)) {
>               ...
>       }

The main reason for not adding your logical xor operator is this:
the other two operators imply sequencing of evaluation, the
logical xor operator can't.

	A && B

means evaluate A and if it is true, evaluate B. The result of the
expression is true (1) if the last expression evaluated is nonzero.

However, your xor operator requires that both operands be
evaluated; this makes it a bad idea to create an operator
analogous to the others.

This is not meant to imply that the functionality of a logical
xor is not useful, only that that syntax would be a bad idea.

If I really needed this functionality, I would create a macro
logxor(a,b), using the expression you specified.  However, it is
rarely the case that I need this for arbitrary arguments;
normally, I do this with logical values and for these the
regular xor (^) operator is sufficient.



More information about the Comp.std.c mailing list