The nonexistent operator (along = v. == lines)

Richard Barnette barnettr at snaggle.rtp.dg.com
Thu Apr 4 04:43:16 AEST 1991


In article <156 at revcan.UUCP> darren at 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 at dg-rtp.dg.com
UUCP:  <your 'world' string here>!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             |



More information about the Comp.lang.c mailing list