I came across an interesting point today in a review over on Code Review. @Veedrac recommened in this answer that variable size types (e.g.
long) be replaced with fixed size types like
uint32_t. Citation from the comments of that answer:
The sizes of int and long (and thus the values they can hold) are platform-dependent. On the other hand, int32_t is always 32 bits long. Using int just means that your code works differently on different platforms, which is generally not what you want.
The reasoning behind the standard not fixing the common types is partially explained here by @supercat. C was written to be portable across architectures, in contrary to assembly which was usually used for systems programming at the time.
I think the design intention was originally that each type other than int be the smallest thing that could handle numbers of various sizes, and that int be the most practical "general-purpose" size that could handle +/-32767.
As for me, I've always used
int and not really worried about the alternatives. I've always thought that it is the most type with best performance, end of story. The only place I thought fixed width would be useful is when encoding data for storage or for transfer over a network. I've rarely seen fixed width types in code written by others either.
Am I stuck in the 70s or is there actually a rationale for using
int in the era of C99 and beyond?