Topic: bool operations (was From C++ to Shining C)
Author: shields@tembel.org (Michael Shields)
Date: 1995/07/15 Raw View
In article <1995Jul13.111446.22483@friend.kastle.com>,
Richard Krehbiel <rich@kastle.com> wrote:
> If bool++ means bool=true then what about bool+=i? Where i is zero?
It would leave bool unchanged. A positive i would set bool true and a
negative i would set it false.
--
Shields.
Author: Michael Cook <mcook@cognex.com>
Date: 1995/07/16 Raw View
>>>>> "MS" == Michael Shields <shields@tembel.org> writes:
MS> In article <1995Jul13.111446.22483@friend.kastle.com>,
MS> Richard Krehbiel <rich@kastle.com> wrote:
>> If bool++ means bool=true then what about bool+=i? Where i is zero?
MS> It would leave bool unchanged. A positive i would set bool true and a
MS> negative i would set it false.
If you implement `bool+=i' in terms of the existing implicit conversions, then
`b+=i' is `b=b+i' is `b=bool(int(b)+i)' is one of
b=bool(0+i)
or
b=bool(1+i)
which has different truth values depending on the value of i and the previous
value of b.
Michael.
Author: shields@tembel.org (Michael Shields)
Date: 1995/07/17 Raw View
In article <MCOOK.95Jul16141925@erawan.cognex.com>,
Michael Cook <mcook@cognex.com> wrote:
> If you implement `bool+=i' in terms of the existing implicit conversions, then
> `b+=i' is `b=b+i' is `b=bool(int(b)+i)' is one of
>
> b=bool(0+i)
> or
> b=bool(1+i)
>
> which has different truth values depending on the value of i and the previous
> value of b.
If you don't add new semantics to bool, why make it a type at all,
when you could just treat an int as a boolean, as people do now?
--
Shields.
Author: Michael Cook <mcook@cognex.com>
Date: 1995/07/17 Raw View
>>>>> "MS" == Michael Shields <shields@tembel.org> writes:
MS> If you don't add new semantics to bool, why make it a type at all,
MS> when you could just treat an int as a boolean, as people do now?
Overloading.
BTW, has someone pointed out yet that `E1 op= E2' is ill formed if E1 is of
type `bool'?
Michael.
Author: rich@kastle.com (Richard Krehbiel)
Date: 1995/07/13 Raw View
shankar@sgi.com (Shankar Unni) wrote:
>bool-- is an undefined operation, and is not guaranteed to set the boolean
>to zero. bool++ will, however, set it to true.
>I guess the intent was that implementations can quietly implement bool as
>"unsigned char" and do nothing else, but that's clearly silly, since they
>would still have to guard against 256 ++'s in a row.
>In practice, I guess most implementations would actually implement bool as
>an unsigned char, with bool++ being changed to bool=true, and bool-- to
>bool=false;
If bool++ means bool=true then what about bool+=i? Where i is zero?
(MHO: Should be illegal. Also IMHO bool++ should be illegal - if you
mean bool=true, damn it, spend the three extra keystrokes and say it
that way.)
--
Richard Krehbiel, Kastle Systems, Arlington VA USA
rich@kastle.com (work) or richk@cais.com (personal)