C ++中int的最小大小是多少?

时间:2018-06-19 14:29:43

标签: c++ standards

Cppreference.com声明:

  

If no length modifiers are present, it's guaranteed to have a width of at least 16 bits.

但是,最新的标准草案只说:

  

Plain ints have the natural size suggested by the architecture of the execution environment.

仅在脚注中添加:

  

int must also be large enough to contain any value in the range [INT_­MIN, INT_­MAX], as defined in the header <climits>.

从标准的这些部分来看,int的大小似乎完全取决于实现。 “最低16位”保证从何而来?

1 个答案:

答案 0 :(得分:4)

int的最小大小源自以下要求:INT_MIN不得小于-32767,并且INT_MAX至少应为+32767。请注意,这是2 ^ 16-1个可能的值,允许带符号的零表示形式的1的补码。