Why there is too many uneccessary casts?
Simen Kjaeraas
simen.kjaras at gmail.com
Tue Jun 11 04:15:11 PDT 2013
On Tue, 11 Jun 2013 12:39:47 +0200, Temtaime <temtaime at gmail.com> wrote:
> There is overflow and it can be with int too.
> It's standard behavior.
Indeed. And a class is a void* is an int is a char is a double? That's
perfectly possible - it's all just memory anyway. D has chosen to do
it like this to prevent common errors. If you think the cast stands
out like a sore thumb, use:
ubyte k = 10;
ubyte c = (k + 1) & 0xFF;
That way, value range propagation ensures the result fits in a ubyte,
and the code compiles happily.
--
Simen
More information about the Digitalmars-d-learn
mailing list