TRUE and FALSE
Felix Lee
flee at guardian.cs.psu.edu
Sun Sep 2 03:48:07 AEST 1990
>#define BOOL( b ) ( (b) ? TRUE : FALSE )
>#define NOT( b ) BOOL( !(b) )
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.
--
Felix Lee flee at cs.psu.edu
More information about the Comp.lang.c
mailing list