flagging unsigned subtraction assigned to bigger signed number?

Steven Schveighoffer schveiguy at gmail.com
Tue May 20 03:41:02 UTC 2025


On Tuesday, 20 May 2025 at 03:11:47 UTC, Steven Schveighoffer 
wrote:
> I just spent about 15 minutes working on a problem where an 
> unsigned subtraction converted to a float caused a totally 
> unexpected value.
>
> I had to printf debug this, because it was happening only at a 
> certain point.
>
> The code was something like this:
>
> ```d
> foreach(i, v; messages) // messages is a string array
> {
>    float vpos = 600 - 30 * (messages.length - i);
>    DrawText(messages.ptr, 100, vpos.to!int, 20, Colors.WHITE);
> }
>
> ```

Typo there, should have been `DrawText(v.ptr, 100, ...)`

-Steve


More information about the Digitalmars-d mailing list