Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-sdd!apollo!lsmith
From: lsmith@apollo.HP.COM (Lawrence C. Smith)
Newsgroups: comp.lang.c++
Subject: Re: Time to standardize "true" and "false"
Message-ID: <45fe2dd3.1199f@apollo.HP.COM>
Date: 2 Oct 89 20:53:00 GMT
References: <12070@cit-vax.Caltech.Edu> <8862@etana.tut.fi> <27541@amdcad.AMD.COM>
Reply-To: lsmith@apollo.HP.COM (Lawrence C. Smith)
Organization: Hewlett-Packard Apollo Division - Chelmsford, MA
Lines: 39

In article <27541@amdcad.AMD.COM> tim@amd.com (Tim Olson) writes:
>In article <8862@etana.tut.fi> pl@etana.tut.fi (Lehtinen Pertti) writes:
>| From article <12070@cit-vax.Caltech.Edu>, by wen-king@cit-vax.Caltech.Edu (King Su):
>| > 
>| > #define bool(a) (!!(a))
>| > 
>| > Then just use bool(X) whenever you wanted to use (bool)X.
>| > 
>| 
>| 	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.
>| 
>| 	Nice, isn't it.  And too real too.
>
>And wrong, too.  Do you know of a compiler that does this in the
>general case?

Yes, all of them.  This is an example of a "cheap" optimization, one that
is relatively easy and safe, most of the time.  The fact that it does not
do what we would expect does not mean it is wrong, either.  !!a == a under
the compiler's own built-in logical rules and if(a) will work the same way.
I don't think there is a compiler in the world I'd trust to take !!a and
turn it into a canonical true/false value.  Come on, people!  C compilers
weren't even required to honor parens until the last ANSI revision, a C
compiler is allowed to do *anything it wants* to a program provided the
final program is congruent to the input program with repect to the compilers
own rules for such changes.  No compiler has to compile a++ if ++a gives
the same result.  No compiler has to compile (a++; b = a-1;) when (b = a++;)
means the same thing.  This isn't new, the floating point fans have been
bitching about this for *years* since it makes C terribly unsafe for
floating point, where round-off can smite you a mighty blow without warning.

Folks, all this is all just adding weight to the "let's add booleans to C"
contingent's argument.
-- 
Larry Smith
  Internet: lsmith@apollo.hp.com
  UUCP:     {decvax,mit-eddie,umix}!apollo!lsmith