Yair Lenga via Gcc wrote on 09/22/25 08:29:
I've inherited an old code base of "C" code, which was maintained by
relatively inexperience team. One of the common pattern that I've seen was:
for (int i=0 ; i < strlen(s) ; i++) { ... }
Such code implies that the string can change between the loop iterations.
This of course is a legit use case.
If the string is not changing, then the programmer instead should use:
for (size_t len = strlen(s), i = 0; i < len; ++i) { ... }
or even better:
const size_t len = strlen(s);
for (size_t i = 0; i < len; ++i) { ... }
size_t exists at least since C99 (1999).