DMD 0.148 release
Regan Heath
regan at netwin.co.nz
Sun Feb 26 12:56:10 PST 2006
On Sun, 26 Feb 2006 18:46:10 +0000 (UTC), Thomas Kuehne
<thomas-dloop at kuehne.cn> wrote:
> Charles schrieb am 2006-02-26:
>>
>> > Can't we simply treat zero as false and non-zero as true as we C
>> > programmers always do?
>>
>> I agree, I still don't get what the 'true bool' fuss is about .
>
> if(b==1) { ... }
>
> instead of
>
> if(b!=0) { ... }
>
> can be found in quite a lot of C code ...
So?
Assuming:
- 'b' is a bool
- a bool can only have 2 values, 'true' and 'false'
- when you convert/promote a bool to an int you get: 'true'->'1',
'false'->'0'
- when you convert/promote an int to bool you get: '0'->false,
'!0'->'true'
Then:
if(b==1) { ... }
results in 'b' being converted to int, giving it the value 1, and the
comparrison working correctly.
Right?
Regan
More information about the Digitalmars-d-announce
mailing list