问题
Cppreference.com claims:
If no length modifiers are present, it's guaranteed to have a width of at least 16 bits.
However, the latest standard draft only says:
Plain ints have the natural size suggested by the architecture of the execution environment.
With the footnote only adding that:
int must also be large enough to contain any value in the range [INT_MIN, INT_MAX], as defined in the header <climits>.
From these sections of the standards, it seems like int
's size is entirely implementation dependent. Where does the "16 bit minimum" guarantee come from?
回答1:
The minimum size for int
follows from the requirement that INT_MIN
shall be no less than -32767
and INT_MAX
shall be at least +32767
. Note that that's 2^16-1 possible values, which allows for 1's complement with signed zero representation.
来源:https://stackoverflow.com/questions/50930891/what-is-the-minimum-size-of-an-int-in-c