c++ - `int` 在 C++ 中默认是 `signed long int` 吗?

标签 c++ types

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, and long 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. Plain ints 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/

相关文章:

types - 为模块定义递归签名

javascript - 为什么我必须为常规 "const"变量指定类型,而不是为 "const"循环中定义的 "for"变量指定类型?

c++ - 从 C++ 中的位数组/位图中读取字段

c++ - 如何获取屏幕的尺寸?

java - 获取类类型为特定类

haskell - 为什么 Haskell 会隐藏同名但类型签名不同的函数?

python - 如何 json 序列化自定义可迭代对象?

c++ - 在 QGraphicsView/QGraphicsScene 中移动 QGraphicsProxyWidget 中的嵌入式小部件

c++ - 在 C++ 中,当被 ctrl-c 中断时,在死亡之前调用带有参数(信号编号除外)的函数

C++输入重载陷入while循环