BigInt bool assign

Mr. Anonymous mailnew4ster at gmail.com
Sat Dec 24 04:46:32 PST 2011


On 24.12.2011 12:33, Don wrote:
> On 24.12.2011 02:30, Derek wrote:
>> On Sat, 24 Dec 2011 09:19:26 +1100, bearophile
>> <bearophileHUGS at lycos.com> wrote:
>>
>>> This is why it's better to avoid casts, not requiring them in the
>>> first place, unless they are useful. In this case I think a cast
>>> introduces more danger than the risks caused by implicit bool->int
>>> conversions.
>>
>> If we assume that explicit casts are required for bool->int conversion,
>> can you show some code in which this could cause a problem?
>
> I think stuff like
> int z += x > y;
> should ideally require a cast. That's a crazy operation.
>
> The problem is compatibility with ancient C code (pre-C99), where you
> may find:
>
> alias int BOOL;
>
> BOOL b = x > y;
>
> Although BOOL is typed as 'int', it really has the semantics of 'bool'.
> We have an example of this in D1's opEquals().
> I think this is reason why implicit conversion bool -> int exists.
>
> BTW, great to see you again, Derek!

The D Programming Language, page 172:
for (; n >= iter * iter; iter += 2 - (iter == 2)) { ...
:)


More information about the Digitalmars-d mailing list