ubyte + ubyte = int
Ali Çehreli
acehreli at yahoo.com
Wed Oct 26 21:19:12 UTC 2022
On 10/26/22 14:10, 0xEAB wrote:
> I guess, this fancy behavior is inherited from C.
Yes. It is called integer promotions:
https://dlang.org/spec/type.html#integer-promotions
(The next section is related as well.)
> I know this is advanced stuff, but the compiler *could* even prove that
> the calculation(s) won’t go beyond `ubyte.max`.
Apparently it does not go that far but there is Value Range Propagation:
https://www.digitalmars.com/articles/b62.html
That article links to this forum post:
https://www.digitalmars.com/d/archives/digitalmars/D/Value_Preservation_and_Polysemy_80224.html#N80293
Ali
More information about the Digitalmars-d-learn
mailing list