Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!sun-barr!decwrl!decvax!ima!esegue!johnl From: johnl@esegue.segue.boston.ma.us (John R. Levine) Newsgroups: comp.lang.c Subject: Re: C history question Keywords: C design, XOR Message-ID: <1989Sep11.144227.258@esegue.segue.boston.ma.us> Date: 11 Sep 89 14:42:27 GMT References: <575@calmasd.Prime.COM> Reply-To: johnl@esegue.segue.boston.ma.us (John R. Levine) Organization: Segue Software, Cambridge MA 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? Because it's nowhere near as useful. The && and || operators are useful because they guarantee left to right short circuit evaluation. You can't find the value of an XOR without evaluating both operands, so short circuit evaluation is meaningless. >[Why have to write] (a || b) && (!(a && b)) when a ^^ b is so much "cleaner"? If you know that a and b actually have the values 0 or 1, typically because they are comparison expressions, you can write either of: a ^ b a != b and get exactly what you want. If they're not strictly 1 or 0, these will do: !a ^ !b !a != !b If this is too ugly, you can always write an XOR(a,b) macro. -- John R. Levine, Segue Software, POB 349, Cambridge MA 02238, +1 617 492 3869 johnl@esegue.segue.boston.ma.us, {ima|lotus}!esegue!johnl, Levine@YALE.edu Massachusetts has 64 licensed drivers who are over 100 years old. -The Globe