Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!uunet!mcsun!ukc!pyrltd!tetrauk!simons From: simons@tetrauk.UUCP (Simon Shaw) Newsgroups: comp.lang.c Subject: Re: TRUE and FALSE Message-ID: <728@tetrauk.UUCP> Date: 7 Sep 90 11:33:09 GMT References: <11215@alice.UUCP> <514@demott.COM> <2316@cirrusl.UUCP> <926@hls0.hls.oz> Reply-To: simons@tetrauk.UUCP (Simon Shaw) Organization: Tetra Ltd., Maidenhead, UK Lines: 35 In article <926@hls0.hls.oz> george@hls0.hls.oz (George Turczynski) writes: >In article , flee@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@tetrauk.uucp