as far I'm concerned it has been an undocumented coding convention so far to
use `int` or `unsigned int` for iterator variables in a loop instead of fixed
width integer types. Does anybody object to adding this to the coding
conventions explicitly?
as far I'm concerned it has been an undocumented coding convention so
far to
use `int` or `unsigned int` for iterator variables in a loop instead of
fixed
width integer types. Does anybody object to adding this to the coding
conventions explicitly?
`size_t` is optimal for every architecture that does not use segmented memory.
The only platform that I know which used segmented memory was 80286, which was
not produced since the mid 90th. According to Wikipedia the last architecture
that used segmented memory died out in 1997.
size_t is the type returned from sizeof() call that you may use to determine any object size (including length of static arrays), so for my understanding the returned size_t value can not exceed the highest possible index for any array that can be allocated on the underlying platform. But as Kaspar suggested we should probably state against using fixed width and only recommend size_t.
... cannot blindly by convention converted to size_t as loop variable.
Of course not.
But I believe the question was more, in case of an unsigned type,
should we use "unsigned int" or size_t. In that case I would go for size_t.
IMHO this example also answers Oleg's initial concern: sometimes int or
unsigned int or size_t just don't work.
In my opinion, integer widths should only be specified in cases where the developer needs to know the exact width, for example in network protocols or when interfacing with hardware. In normal program logic the variables should be using the general types, such as int, long, double, or size_t. This goes for code in general, not just iterator variables.