TRUE and FALSE

Floyd McWilliams fmcwilli at oracle.oracle.com
Fri Sep 7 01:48:19 AEST 1990


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 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 at 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



More information about the Comp.lang.c mailing list