Path: utzoo!attcan!uunet!husc6!mailrus!uflorida!novavax!proxftl!bill From: bill@proxftl.UUCP (T. William Wells) Newsgroups: comp.std.c Subject: Re: the logical xor operator! Summary: no, it does not fit Message-ID: <407@proxftl.UUCP> Date: 3 Jul 88 02:08:27 GMT References: <1719@ogcvax.ogc.edu> <1309@ark.cs.vu.nl> <1310@ark.cs.vu.nl> Organization: Proximity Technology, Ft. Lauderdale Lines: 35 In article <1310@ark.cs.vu.nl>, maart@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.