int
在 C++ 中默认是 signed long int
吗?
它是否依赖于平台和/或编译器?如果有,怎么做?
[编辑]
以下任何一项都可以保证是重复的吗?
signed short int
signed int
signed long int
signed long long int
unsigned short int
unsigned int
unsigned long int
unsigned long long int
最佳答案
plain int
已签名,是否与 long int
大小相同取决于平台。
保证的是
sizeof (int) <= sizeof (long)
并且 int
足够大,至少可以容纳从 -32767 到 32767 的所有值。
标准内容:([basic.fundamental]
部分:
There are five standard signed integer types :
signed char
,short int
,int
,long int
, andlong long int
. In this list, each type provides at least as much storage as those preceding it in the list. There may also be implementation-defined extended signed integer types. The standard and extended signed integer types are collectively called signed integer types. Plainint
s have the natural size suggested by the architecture of the execution environment; the other signed integer types are provided to meet special needs.
关于c++ - `int` 在 C++ 中默认是 `signed long int` 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8674743/