On 12/24/2011 11:33 AM, Don wrote:
On 24.12.2011 02:30, Derek wrote:
On Sat, 24 Dec 2011 09:19:26 +1100, bearophile
<[email protected]> 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.
What does anyone gain by adding bulky 'cast(int)' noise to their code
that is nothing but a no-op?
That's a crazy operation.
s/craz/nift/
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.
It exists because it is handy and makes sense. Would you also want to
ban implicit short -> int conversion?
BTW, great to see you again, Derek!