|
|
|
|
|
by mananaysiempre
1392 days ago
|
|
As Jens Gustedt points out[1], the following intentional unsigned overflow works perfectly for downwards iteration (even when length is 0 or SIZE_MAX), though it looks a bit confusing at first: for (size_t i = length - 1; i < length; i--) ...
You are also free to start at any other (not necessarily in-bounds) index, just like with ascending iteration.[1] https://gustedt.wordpress.com/2013/07/15/a-praise-of-size_t-... |
|
Also, that behavior is not guaranteed. The programmer would need to be aware of how the particular machine in question actually handles that.
Then again, that's C.