Here is a loop that goes through a C string backwards:
size_t slen = strlen(string);
for (size_t i = slen-1; i >= 0; i--) {
/* do stuff */
}
And when I compile this code with gcc -Wall -Wextra -std=c99 -o code code.c
, I receive this warning:
warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
When dealing with this warning, I replaced this loop with instead:
for (int i = (int)slen-1; i >= 0; i--) {
Which works fine, but I was wondering if their was a way to make the first loop still compile without the warning above? This warning only seems to trigger when I compile with -Wextra
.