Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!killer!vector!rpp386!jfh From: jfh@rpp386.UUCP (John F. Haugh II) Newsgroups: comp.std.c Subject: Re: the logical xor operator! Message-ID: <3254@rpp386.UUCP> Date: 26 Jun 88 15:29:06 GMT References:<1719@ogcvax.ogc.edu> <1309@ark.cs.vu.nl> <1310@ark.cs.vu.nl> Reply-To: jfh@rpp386.UUCP (The Beach Bum) Organization: Big "D" Home for Wayward Hackers Lines: 40 In article <1310@ark.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: >Of course the way to come around the deficiency is: > > if (!(expr1) != !(expr2)) { > ... > } > >but this only works if !0 always evaluates to the same value (viz. 1), that is, >the optimizer is not allowed to f*ck around with the comparison. >!0 is indeed a constant, isn't it? >-- >I'd rather live in Russia |Maarten Litmaath @ Free U Amsterdam: > than in South-Africa... |maart@cs.vu.nl, mcvax!botter!ark!maart [ hey, chris, here is topic #2 for your posting ] which, as this discussion went a few months ago, is exactly the case. the code you've writen above, modulo any blindness on my part, should work perfect as an exclusive-or function. remember, exclusive-or is the not-equivalant operator, it returns true when the two operands are not boolean equivalant. the implied comparision against zero is performed automagically in the case of || and &&. as far as the optimizer is concerned, it should still be able to perform any optimizations which would be allowed for any other boolean operators, except you can't short circuit != or == as you can && and ||. in particular, i believe (a == 0)^(b == 0) most likely can't be as well optimized as (a == 0)!=(b == 0). i can't prove this to be true, but i very well suspect it may be. - john. ps - your .signature is thought provoking. i can't decide whether i'd rather live in a large communist country which oppresses blacks or a small capitalist country which oppresses blacks. hard choice. -- John F. Haugh II +--------- Cute Chocolate Quote --------- HASA, Division "S" | "USENET should not be confused with UUCP: killer!rpp386!jfh | something that matters, like CHOCOLATE" DOMAIN: jfh@rpp386.uucp | -- with my apologizes