So I\'m using size_t
instead of int
in any indexing for loop to prevent negative indices. But when counting down, this leads to an overflow:
The problem is that in in your implementation size_t has type unsigned long
or unsigned int
.
When i=0 the condition is accomplished and --i will transform it to 4294967295UL = ULONG_MAX, so the test condition i >= 0
from the loop will never be false .
size_t has some unsigned type, i will never be negative.