VRP and signed <-> unsigned conversion

Kagamin spam at here.lot
Thu Dec 16 09:56:52 UTC 2021


On Wednesday, 15 December 2021 at 14:39:09 UTC, Steven 
Schveighoffer wrote:
> 2. If the above rewrite is possible, shouldn't VRP just allow 
> this conversion? i.e. a type that has an unsigned/signed 
> counterpart should be assignable if the signed/unsigned can 
> accept the range.

In your case the value is int typed and when a negative int value 
is converted to ubyte, you lose upper 3 bytes. It's more like

```
ubyte f()
{
    int n=-15;
    return n;
}
```

Well, even this doesn't compile:
```
ubyte f()
{
    return -15;
}
```


More information about the Digitalmars-d mailing list