Re: bool and == by Chen
Chen
Sun Jun 20 10:15:58 CDT 2004
No, no, you mistunderstood me. I don't like the fake integer bool at all...
It's a big waste of memory using them ;-). But, many library functions is
still using them...
// Chen
"Arnaud Debaene" <adebaene@club-internet.fr> skrev i meddelandet
news:OrdffsgVEHA.2544@TK2MSFTNGP10.phx.gbl...
> Chen wrote:
> > But... what happens if you do this...
> >
> >
> > int iA = 2;
> > bool bA;
> > bA = iA;
> >
> >
> > is bA == true there?
> Yes. There is an implicit conversion from int to bool, mainly here for
> historical reasons. 0 becomes false, and any non-zero value becomes true.
>
> > And, what happens if you do this?
> >
> > memset(&bA,2,sizeof(bool));
>
> Undefined. Just as if you would do :
> float f;
> memset(&f, 1, sizeof(float));
>
> Why do you insist on having an integer representation for bool? bools are
> either true or false, period.
>
> Also, as Alexander has said, every == operation in C++ yeilds to abool,
> whatever the compared types.
>
> Arnaud
> MVP - VC
>
>