From my research, these were the only guarantees that I could find about these built-in integer data types:
char
will not be smaller than 8 bitsshort
will not be smaller than 16 bitsshort
will not be smaller thanchar
In practice, according to my experience, short
is always double the size of char
, but it does not appear that this is a guarantee made by the C language specification. It seems that a scenario such as a 16 bit char
and a 16 bit short
could still be valid.
This is more of a curiosity question, I realize that if you really need exact widths for your integer data types, you're better off using the stdint.h
header.
UPDATE 5/6/2021: I do not believe this question is a duplicate of What platforms have something other than 8-bit char?. I am not asking about the specific size of a char
, but rather the ratio between a char
and a short
, regardless of the actual size of either one. At least for me, many of these answers have enlightened me in a way that the "duplicate" question has not. I hope this also helps others that stumble upon it.