TRUE and FALSE
George Turczynski
george at hls0.hls.oz
Tue Sep 11 11:16:49 AEST 1990
In article <728 at tetrauk.UUCP>, simons at tetrauk.UUCP (Simon Shaw) writes:
> In article <926 at hls0.hls.oz> george at hls0.hls.oz (George Turczynski) writes:
> >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))
No, I think not. These macros all return a result that is TRUE or FALSE.
The bitwise XOR operator will not always produce the result TRUE or FALSE.
These macros are not performing bitwise arithmetic, but logical arithmetic.
> with this assumption (TRUE==1, FALSE==0), are there any circumstances
> where the use of the bitwise operator would be unsafe ?
In this case, yes. If someone were to say:-
if( CXOR(a,b) == TRUE )
they would in most cases be in trouble, if the XOR operator was used. Now,
you and I both know that few people would construct it like that, but that
is beside the point, these macros ALWAYS result in TRUE or FALSE.
> 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 ?
Don't think for one second that I would entertain the idea of using these macros !
Felix Lee posted his set, some of which expanded to 200,000++ characters.
Thinking this was ridiculous, and that I might save some people wasting too
much of their time, I posted the same (but improved) macro set, that didn't
waste so much space.
I agree, don't waste your time with the above macros. (But Felix Lee could
at least use the sensible ones, not the 200,000++ char ones :-})
--
| 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