flagging unsigned subtraction assigned to bigger signed number?

kdevel kdevel at vogtner.de
Wed May 21 19:43:45 UTC 2025


On Wednesday, 21 May 2025 at 04:44:35 UTC, Walter Bright wrote:
> 1. use `size_t` for all indices and pointer offsets
>
> 2. use `ptrdiff_t` for all deltas of the form `size_t - size_t`

Thanks for that advice!

> [...]
> You could also do this:
> ```d
> foreach_reverse(ptrdiff_t i, v; messages) // messages is a 
> string array
> {
>     float vpos = 600 - 30 * i;
>     DrawText(messages.ptr, 100, vpos.to!int, 20, Colors.WHITE);
> }
> ```
> but one could argue it's a bit too clever.

Looks okay. Or is the `reverse` part of the cleverness? I mean the
ordinary (forward) foreach also seem to work.


More information about the Digitalmars-d mailing list