logoalt Hacker News

randomblock1 • today at 3:10 AM • 1 reply • view on HN

I thought most people used the explicit version:

  for (size_t i = count; i > 0; --i) {
      // use array[i - 1]
  }
You can also do something like:

  size_t index = i - 1;
to not have to use i-1. I believe the compiler optimizes that out anyway to be identical.

Replies

seeknotfind • today at 3:28 AM

Yes, this is the best answer. This also works with `-fsanitize=unsigned-integer-overflow`.