What is the minimum size of an int in C++?

情到浓时终转凉″ 提交于 2019-12-14 04:22:49

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!