On 18/11/2019 10.25, Markus Armbruster wrote: > Philippe Mathieu-Daudé <phi...@redhat.com> writes: > > [...] >> The related question is, is it OK to use size_t to iterate over an array? >> >> for (size_t i = 0; i < ARRAY_SIZE(array); i++) { >> ... >> } > > My rule of thumb on integer types is "whatever lets me avoid > not-obviously-safe conversions (implicit ones in particular) with the > least type cast clutter. > > Quite often, int fits the bill. But not always. > > To reply to your example: depends on what's hiding in the ... :)
The problem here is that ARRAY_SIZE() gives you an size_t, so the compiler might complain about comparing signed int with unsigned size_t. Thus if i is only used as array index in the "..." part, I think it's fine to use size_t for i here. Thomas