TRUE and FALSE

George Turczynski george at hls0.hls.oz
Thu Sep 6 10:59:51 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.

I don't think you'll find many compilers that are happy with those  
extremely inefficient macros.  Whether or not it compiles is one thing, 
but how long it takes is another ! 
 
I think that anything that expands to a 200,000 oharacter or so long 
expression is ridiculous, but that's my opinion :-)
 
Let me ask why you chose to use "!" and "&&" and ignored "||" ? Do
you not trust it or something ?  It is just as valid in C as "!" and
"&&" !
 
It is not clever to create such nonsensical macros.
 
Why not try these:
 
#define FALSE          0
#define CNOT(a)        (!(a)) 
#define CAND(a,b)      ((a)&&(b)) 
#define CNAND(a,b)     CNOT(CAND(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)) 
#define CXNOR(a,b)     COR(CAND(a,b),CNOR(a,b)) 
#define CEQUIV(a,b)    CXNOR(a,b)    
#define TRUE           CNOT(FALSE) 
#define ISTRUE(a)      CAND(a,TRUE) 
#define ISFALSE(a)     CNOT(ISTRUE(a)) 
 
I too have used but one of each of "0", "!", "&&", and "||" as well.

Now, I can show you what these expand to, because they aren't ridiculously
long:

0
(!(a))
((a)&&(b))
(!(((a)&&(b))))
((a)||(b))
(!(((a)||(b))))
(!(((((a)&&(b)))||((!(((a)||(b))))))))
((((a)&&(b)))||((!(((a)||(b))))))
((((a)&&(b)))||((!(((a)||(b))))))
(!(0))
((a)&&((!(0))))
(!(((a)&&((!(0))))))

respectively.

Now, if anyone feels that they MUST use macros like these, use mine,
or even better, make your own up not defining them in terms of each
other, but in terms of "0", "!", "&&" and "||" (This will remove any
pairs of redundant parentheses).

Have a nice day...

-- 
| George P. J. Turczynski.          |---------------------------------------------------- 
| Computer Systems Engineer.        | ACSnet: george at highland.oz | I can't speak for the |
| Highland Logic Pty. Ltd.          | Phone: +61 48 683490       | company, I can barely |
| Suite 1, 348-354 Argyle St        | Fax:   +61 48 683474       | speak for myself...   |
| Moss Vale. NSW. Australia. 2577   |---------------------------------------------------- 



More information about the Comp.lang.c mailing list