Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!mcsun!ukc!edcastle!aiai!ken From: ken@aiai.ed.ac.uk (Ken Johnson) Newsgroups: comp.lang.c Subject: XOR operator (was Re: C history question) Keywords: C design, XOR Message-ID: <866@skye.ed.ac.uk> Date: 11 Sep 89 16:25:15 GMT References: <575@calmasd.Prime.COM> Reply-To: ken@aiai.UUCP (Ken Johnson) Followup-To: comp.lang.c Organization: AIAI, University of Edinburgh, Scotland Lines: 27 In article <575@calmasd.Prime.COM> wlp@calmasd.Prime.COM (Walter Peterson) writes: >C has bitwise operators for AND (&), OR (|) and XOR (^) and boolean >operator for AND (&&) and OR (||), but not for XOR (^^). [...] Why >make people go to the trouble of writing something like >(a || b) && (!(a && b)) when a ^^ b is so much "cleaner". I can't tell you why ^^ isn't in the language, but note that A^^B would probably have a property that the above longer expression does not have, namely: A && B and A || B each evaluate the second argument only if necessary, and at most once. In some cases, evaluating A ^^ B by your suggested method would require evaluating A or B more than once. So a more suitable expression might be int X1, Y1; if ((X1 = A) && (!(X2 = B))) || (X2 && !X1) {...} Or you could just use goto's -- I think they would be justified here if you explain what they do. -- Ken Johnson, AI Applications Institute, 80 South Bridge, Edinburgh EH1 1HN E-mail ken@aiai.ed.ac.uk, phone 031-225 4464 extension 212 `I have read your article, Mr. Johnson, and I am no wiser than when I started.' -- `Possibly not, sir, but far better informed.'