Why do I have to cast arguments from int to byte?

Adam D. Ruppe destructionator at gmail.com
Tue Oct 10 21:04:53 UTC 2017


On Tuesday, 10 October 2017 at 19:55:36 UTC, Chirs Forest wrote:
> Why?

D inherited a silly rule from C where any arithmetic is promoted 
to int first.

The big difference is D doesn't do implicit narrowing 
conversion... so x + 1 becomes int, but then int to byte requires 
an explicit cast (unless the compiler can prove the range in that 
particular expression - this is called "value range propagation").

I think it has proved to be a bit of a mistake :(


More information about the Digitalmars-d-learn mailing list