Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!decwrl!fernwood!oracle!news From: fmcwilli@oracle.oracle.com (Floyd McWilliams) Newsgroups: comp.lang.c Subject: Re: TRUE and FALSE Message-ID: <1990Sep6.154819.8211@oracle.com> Date: 6 Sep 90 15:48:19 GMT References: <11215@alice.UUCP> <514@demott.COM> <2316@cirrusl.UUCP> <3835@sactoh0.SAC.CA.US> <26280@mimsy.umd.edu> <11474@crdgw1.crd.ge.com> <1990Aug31.145853.6125@cs.eur.nl> Reply-To: fmcwilli@oracle.com (Floyd McWilliams) Organization: Oracle Corporation, Belmont, CA Lines: 42 In article flee@guardian.cs.psu.edu (Felix Lee) writes: |Personally, I use this set of macros: |#define FALSE 0 |#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))) |#define CEQUIV(a,b) CNOT(CXOR(a,b)) |#define COR(a,b) CEQUIV(a,CNAND(CNOT(a),CXOR(a,b))) |#define CAND(a,b) CXOR(COR(a,b),CXOR(a,b)) |#define TRUE COR(FALSE,CNOT(FALSE)) |#define ISTRUE(a) CAND(TRUE,a) |#define ISFALSE(a) CNOT(ISTRUE(a)) |These may unfortunately overrun some compiler or preprocessor limits |(TRUE expands to an 853 character expression, and ISFALSE(x) expands |to 203677 characters). But they're otherwise quite portable, and I |find the prefix style much more readable than C's cryptic infix |expressions, especially when used in conjunction with a set of macros |that provide LISP-ish control structures. Plus, the definitions are intuitively obvious! One can only pity the programmers who use such twisted constructs as if (!a) /* If not a */ if (a || b) /* If a or b */ if (a && b) /* If a and b */ and the unthinkable if (a) /* If a is true */ p.s. Felix, while it's true that TRUE is FALSE OR NOT FALSE, it also happens to be NOT FALSE AND NOT FALSE. So for _maximum_portability_, you should have #define TRUE CAND(COR(FALSE,CNOT(FALSE)),CAND(CNOT(FALSE),CNOT(FALSE))) -- Floyd McWilliams -- fmcwilli@oracle.com "I don't mind anybody dropping out of anything, but it's the imposition on somebody else I don't like. The moment you start dropping out and then begging off somebody else to help you, then it's no good." -- George Harrison