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

Moritz Maxeiner moritz at ucworks.org
Tue Oct 10 20:36:37 UTC 2017


On Tuesday, 10 October 2017 at 19:55:36 UTC, Chirs Forest wrote:
> I keep having to make casts like the following and it's really 
> rubbing me the wrong way:
>
> void foo(T)(T bar){...}
>
> byte bar = 9;
>
> [...]
>
> Why?

Because of integer promotion [1], which is inherited from C.

[1] https://dlang.org/spec/type.html#integer-promotions


More information about the Digitalmars-d-learn mailing list