Time to standardize "true" and "false"

Walter Bright bright at Data-IO.COM
Sat Sep 30 04:35:29 AEST 1989


In article <8862 at etana.tut.fi> pl at etana.tut.fi (Lehtinen Pertti) writes:
<From article <12070 at cit-vax.Caltech.Edu>, by wen-king at cit-vax.Caltech.Edu (King Su):
<< #define bool(a) (!!(a))
<	Then suddenly just behind the corner cames C-compiler from
<	ACME-corporation and realizes '!!a' -< negation of negation is
<	same as original -< we can optimize it away.
If a compiler thought that (!!a) == (a), then it is a compiler bug.
<	Nice, isn't it.  And too real too.
If you run up against such wretchedness, you can do this:

#if ACME_C
#define bool(a)	((a) != 0)	/* if desperate try ((a)?1:0)	*/
#else
#define bool(a) (!!(a))
#endif

I have a copy of K&R which I believe is a first printing. It *clearly*
states that ! is to return 1 or 0. Not -1. Not implementation defined.
Using ! is portable. If it doesn't work with your C, treat it like any
other compiler bug.

If anyone knows of a *current* C compiler that has a problem with this,
please email me. I'm curious!



More information about the Comp.lang.c mailing list