Topic: ordering of boolean type
Author: h.b.furuseth@usit.uio.no (Hallvard B Furuseth)
Date: 23 Jun 1994 17:48:34 GMT Raw View
In article <9417017.28556@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus Henderson) writes:
> dat92mha@ludat.lth.se (Mattias Hallberg) writes:
> >itz@crl.com (Ian T. Zimmerman) writes:
> >> Ronald F. Guilmette <rfg@netcom.com> wrote:
> >> >Oh well. I can still use `enum Bool { False, True };'.)
> [...]
> >> enum Bool { True, False }; 8-/
> [...]
> >> Bool b3 = (Bool) (b1 <= b2);
> >>
> >> has the intuitive meaning ("if b2 then b1").
> >
> >But:
> >Bool b3 = (Bool)(3<10); // will be false
>
> So we should use
>
> enum Bool { True = -1, False = 0 };
but now True != (!False).
--
Hallvard
Author: clamage@taumet.Eng.Sun.COM (Steve Clamage)
Date: 19 Jun 1994 22:35:02 GMT Raw View
In article p65@crl3.crl.com, itz@crl.com (Ian T. Zimmerman) writes:
>In article <rfgCrL3Bw.986@netcom.com>,
>Ronald F. Guilmette <rfg@netcom.com> wrote:
>>so smart. Oh well. I can still use `enum Bool { False, True };'.)
>>
>Actually, you want
>
>enum Bool { True, False }; 8-/
>
>then
>
>Bool b1, b2;
>....
>Bool b3 = (Bool) (b1 <= b2);
>
>has the intuitive meaning ("if b2 then b1").
Unfortunately it has unintuitive meanings as well:
Bool b = True;
if( b ) {
// does NOT execute this code
}
Because zero is equivalent to false in C and C++, you get unmaintainable
code if you define false to be anything but zero.
This whole discussion is now moot. The C++ Committee has adopted a built-in
boolean type called "bool", and the keywords false (which has the value
zero) and true (which has the value 1) of type bool.
The changes fit into the language in such a way that any program which uses a
user-defined boolean type with enums or consts or literals should continue
to work correctly if modified to use the built-in types instead.
What to do during the transition period? Try this:
#ifdef NO_BOOL
enum bool { false, true };
#endif
Then #define NO_BOOL when you use a compiler which doesn't support bool.
Alternative spellings suggest themselves :-)
---
Steve Clamage, stephen.clamage@eng.sun.com
Author: itz@crl.com (Ian T. Zimmerman)
Date: 18 Jun 1994 21:34:13 -0700 Raw View
In article <rfgCrL3Bw.986@netcom.com>,
Ronald F. Guilmette <rfg@netcom.com> wrote:
>so smart. Oh well. I can still use `enum Bool { False, True };'.)
>
Actually, you want
enum Bool { True, False }; 8-/
then
Bool b1, b2;
...
Bool b3 = (Bool) (b1 <= b2);
has the intuitive meaning ("if b2 then b1").
--
Ian T Zimmerman +-------------------------------------------+
P.O. Box 13445 I With so many executioners available, I
Berkeley, California 94712 I suicide is a really foolish thing to do. I
USA +-------------------------------------------+
Author: dat92mha@ludat.lth.se (Mattias Hallberg)
Date: 19 Jun 1994 04:51:54 GMT Raw View
In article p65@crl3.crl.com, itz@crl.com (Ian T. Zimmerman) writes:
> In article <rfgCrL3Bw.986@netcom.com>,
> Ronald F. Guilmette <rfg@netcom.com> wrote:
> >so smart. Oh well. I can still use `enum Bool { False, True };'.)
> >
> Actually, you want
>
> enum Bool { True, False }; 8-/
>
> then
>
> Bool b1, b2;
> ....
> Bool b3 = (Bool) (b1 <= b2);
>
> has the intuitive meaning ("if b2 then b1").
But:
Bool b3 = (Bool)(3<10); // will be false
enum bool{false, true};
is more intuitive I think.
/Mattias Hallberg
dat92mha@ludat.lth.se
Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Sun, 19 Jun 1994 07:03:37 GMT Raw View
dat92mha@ludat.lth.se (Mattias Hallberg) writes:
>itz@crl.com (Ian T. Zimmerman) writes:
>> Ronald F. Guilmette <rfg@netcom.com> wrote:
>> >Oh well. I can still use `enum Bool { False, True };'.)
[...]
>> enum Bool { True, False }; 8-/
[...]
>> Bool b3 = (Bool) (b1 <= b2);
>>
>> has the intuitive meaning ("if b2 then b1").
>
>But:
>Bool b3 = (Bool)(3<10); // will be false
So we should use
enum Bool { True = -1, False = 0 };
to get the best of both worlds ;-)
--
Fergus Henderson - fjh@munta.cs.mu.oz.au