Shouldn't bool be initialized to 0xFF ?
Lionello Lunesu
lio at lunesu.remove.com
Wed Aug 16 03:05:39 PDT 2006
Kirk McDonald wrote:
> Lionello Lunesu wrote:
>> I've been following those "why's char init'ed to -1?" / "why's float
>> init'ed to NaN?" thread, and I'd have to agree with Walter: a crazy
>> initialization sure makes it obvious where the problem lies.
>>
>> So: why isn't "bool" initialized to 0xFF too? In dmd v0.164, bool.init
>> is 0, which is a valid value for bool. For byte/int/long I get it,
>> since there is no invalid value for byte/int/long. But for bool there
>> is, so the same reasoning as char/float applies.
>>
>> We could even name 0xFF "Not A Bool" ;)
>>
>> L.
>
> void main() {
> bool b; // b is 0xFF
> if (b) { // Is b true or false?
> // ...
> }
> }
>
void main() {
bool b; // b is 0x00
if (b) { // Is b true or false?
// ...
}
}
L.
More information about the Digitalmars-d
mailing list