DMD 0.148 release
Derek Parnell
derek at psych.ward
Sun Feb 26 13:48:11 PST 2006
On Mon, 27 Feb 2006 07:56:10 +1100, Regan Heath <regan at netwin.co.nz> wrote:
> 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?
If it implemented that way, yes. However the problem with
if(b == 1)
is that the reader (future maintainer) might be mislead into thinking that
'b' is an integer and may try to use it as such by mistake. It is better
to inform the reader about the true nature of 'b' by writing
if (b == true)
in or to remove such ambiguity.
--
Derek Parnell
Melbourne, Australia
More information about the Digitalmars-d-announce
mailing list