the logical xor operator!

Karl Heuer karl at haddock.ISC.COM
Wed Jun 29 03:28:32 AEST 1988


Let's leave the political discussions in a different newsgroup, okay?

In article <1312 at ark.cs.vu.nl> maart at cs.vu.nl (Maarten Litmaath) writes:
>Karl W. Z. Heuer writes:
>>"Why wasn't logical xor added to ANSI C?".  The answer is that it isn't
>>useful enough to be worth the change to the language.
>
>Well, it's strange K&R didn't think of it in the first place...

"Why didn't K&R make a logical xor operator?" is a different question.  I'll
be glad to take this up in comp.lang.c after I return from vacation.

>Furthermore, it can be implemented WITHOUT breaking existing code,

This (or a weakened form of it) is a necessary condition for ANSI acceptance,
but it is not sufficient.

>and (admittedly) sometimes one would wish for ^^; but then again: isn't Karl
>having problems himself to get \c accepted by ANSI? :-)

It's hard to get anything new accepted by X3J11.  This is as it should be.

Do you want this operator just for completeness, or do you think you'd
actually use it a lot?  I can only think of one routine I've ever written in
which I've needed a logical xor, and since both operands were boolean I simply
used "^".

>>(and I hold the opinion that nothing else [but a normalized boolean] should
>>be handed to a logical operator)
>
>Come on Karl, what's so terrible about the following common practice?
>	if (some_pointer && ...) { ... }

Well, since you asked: The problem with it is that, by looking at this code
fragment in isolation, it's not obvious that some_pointer is a pointer, rather
than an integer, a character, a real, or a boolean.  If you explicitly write
	if (p != NULL && i != 0 && c != '\0' && r != 0.0 && b) { ... }
the reader has more information, which often makes the code more readable.

As I said, this is my personal opinion; I certainly don't think that the
language should be changed to enforce it.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.std.c mailing list