VRP and signed <-> unsigned conversion

Kagamin spam at here.lot
Thu Dec 16 10:00:30 UTC 2021


On Wednesday, 15 December 2021 at 18:43:38 UTC, Steven 
Schveighoffer wrote:
> The impetus of VRP was simple -- C allows implicit casting 
> between *all* integer types. D did not want to do that due to 
> the errors it causes. However, since integer promotion is 
> mimicked from C, all math is done at integer level (this makes 
> C code that's compiled with D code behave similarly). However, 
> it's quite painful to have to cast everything with integers 
> that are smaller than 32-bit ints, so VRP is used to assist in 
> making sure you don't have to cast if the compiler can prove 
> the value fits.

If you want proofs, D has safe conversions:
```
ubyte foo(ubyte a, ubyte b)
{
    return byte((a & 0xf) - (b & 0xf));
}
```


More information about the Digitalmars-d mailing list