logoalt Hacker News

MaulingMonkey • today at 9:18 AM • 0 replies • view on HN

If you want -3 -2 -1 0 and +3 +2 +1 0 from the same operation, you'll need something more complicated (either some nonsense to give you a signed stride/step value among other things — or perhaps just writing the damn loop twice instead of getting too clever.)

However, if you just want -1 to not iterate down to `std::numeric_limits<ssize_t>::min()` — and then invoke undefined behavior by signed integer underflow if `i` happens to be `ssize_t` instead of `size_t` — I'll note that the `i --> 0` will terminate immediately, unlike `i --` as otherwise seen. (unless you feed it `min()` exactly. Then it'll underflow a signed integer before the comparison, so that's still undefined behavior.)