Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!bcm!convex!texsun!newstop!sun!amdcad!dgcad!dg-rtp!snaggle!barnettr From: barnettr@snaggle.rtp.dg.com (Richard Barnette) Newsgroups: comp.lang.c Subject: Re: The nonexistent operator (along = v. == lines) Keywords: xor Message-ID: <1991Apr3.184316.11559@dg-rtp.dg.com> Date: 3 Apr 91 18:43:16 GMT References: <156@revcan.UUCP> Sender: usenet@dg-rtp.dg.com (Usenet Administration) Organization: Data General Corporation, RTP, NC. Lines: 36 In article <156@revcan.UUCP> darren@revcan.UUCP (Darren Morbey) writes: >I've noticed in my writing C code that there is no such operator >as ^^ (which would be to ^ as || is to |). I feel in this case >I *have* to write a macro for this *nonexistent* operator (you may >recall I wrote #define XOR(a,b) ((a)^(b)) ). However... It can't be done. The truth or falseness of a ^ expression cannot be determined without evaluating all the operands. Note the truth tables below: A B | A XOR B A B | A AND B A B | A AND B -----+--------- -----+--------- -----+--------- F F | F F F | F F F | F F T | T F T | T F T | F T F | T T F | T T F | F T T | F T T | T T T | T Given A if F, A AND B is always F; given A is T, A OR B is always T. No such statement can be made for A XOR B; if A is T, A XOR B is NOT B; if A is F, A XOR B is B. In either case the value depends on B regardless of the value of A. ------------------------------------------------------- Richard Barnette | Data General Corporation Commercial Languages | 62 T.W. Alexander Drive (919) 248-6225 | RTP, NC 27709 ------------------------------------------------------- Inet addr: barnettr@dg-rtp.dg.com UUCP: !mcnc!rti!dg-rtp!barnettr ------------------------------------------------------- obligatory (in)famous quote: "You wascal wabbit! Wandering wizards won't win!" - /usr/lib/sendmail /-------------------------------------------------------\ | Richard Barnette | Data General Corporation | | Commercial Languages | 62 T.W. Alexander Drive | | x 6225 | RTP, NC 27709 |