TRUE and FALSE
Simon Shaw
simons at tetrauk.UUCP
Fri Sep 7 21:33:09 AEST 1990
In article <926 at hls0.hls.oz> george at hls0.hls.oz (George Turczynski) writes:
>In article <F4u9._?1 at cs.psu.edu>, flee at guardian.cs.psu.edu (Felix Lee) writes:
>
>> Personally, I use this set of macros:
>> #define CNAND(a,b) (!((a)&&(b)))
>> #define CNOT(a) CNAND(a,a)
>> #define CXOR(a,b) CNAND(CNAND(a,CNOT(b)),CNAND(b,CNOT(a)))
>
>Why not try these:
>
>#define CNOT(a) (!(a))
>#define CAND(a,b) ((a)&&(b))
>#define COR(a,b) ((a)||(b))
>#define CNOR(a,b) CNOT(COR(a,b))
>#define CXOR(a,b) CNOR(CAND(a,b),CNOR(a,b))
If because the value returned by an expression of the form (a == b)
is _defined_ to be 0 or 1, we are defining TRUE as 1 and ZERO as 0
(no contention yet, I hope), then the worst of these expansions,
XOR, should be contracted by the use of the bitwise XOR.
#define CXOR(a,b) ((a)^(b))
with this assumption (TRUE==1, FALSE==0), are there any circumstances
where the use of the bitwise operator would be unsafe ?
IMHO, the compounds NOR and NAND, while much more useful if constructing
electronic circuitry, are considerably less clear in code (Not to mention
XNOR, which even now takes me a few seconds to work out). Lets not
forget the poor sods who've got to maintain this code !
Anyone disagree ?
--
Simon Shaw ; simons at tetrauk.uucp
More information about the Comp.lang.c
mailing list