vrp bug?
Forum User
forumuser at example.com
Sun Jun 14 11:51:21 UTC 2026
On Sunday, 14 June 2026 at 09:06:13 UTC, Kagamin wrote:
> ```
> char BitsToChar(in uint bit5)
> {
> const uint b=bit5&0x1f;
> return b<10?'0'+b:'a'+(b-10);
> }
> ```
> This code can't implicitly convert to char, but a version
> without parentheses `'a'+b-10` can. Is this intended or I miss
> something?
```
(b - 10)
```
has type `uint` and wraps if `b` < 10.
```
'a' + b - 10
```
is evaluated left to right, `b` is < 32, so `'a' + b` is < 129.
Substract 10 and the expression is < 119. It fits in the range of
char.
But the whole thing is questionable:
- Drop the `const` in `b`'s declaration and the Error shows up
in
the unparenthesized version, too.
- try `+127` and `+128` instead of `-10`.
More information about the Digitalmars-d-learn
mailing list