Path: utzoo!utgpu!water!watmath!clyde!bellcore!faline!ulysses!allegra!mit-eddie!uw-beaver!uw-june!pardo From: pardo@uw-june.UUCP Newsgroups: comp.lang.c Subject: Re: "logical" xor Message-ID: <3970@uw-june.UUCP> Date: 11 Jan 88 23:25:14 GMT References: <11207@brl-adm.ARPA> <20153@teknowledge-vaxc.ARPA> Reply-To: pardo@uw-june.UUCP (David Keppel) Organization: U of Washington, Computer Science, Seattle Lines: 30 Posted: Mon Jan 11 18:25:14 1988 [ use "!=" for "^^" (logical xor) ] Only works if the values you have are already 1/0 valued. As with "^" (bitwise xor) int x = 3, y = 4; assert( x ^^ y == 0); assert( (x != y) == 1); [ somebody else: logical xor is hard to optimize ] True, in general, but the compiler (say, through flow analysis) may be able to determine that one or both of the "^^" operands has just been set by something that guarantees the result to be 0 or 1, in which case the compiler can (safely!) reduce "^^" to "^". I vote that if (a ^^ b) ... is clearer than if ((a == 0) != (b == 0)) ... or whatever the equivalent xor expression of choice happens to be. ;-D on (My favorite sintax: switch(x+=*a+++*b){...}) Pardo