sizeof(int)
在我的 Dev Cpp
上显示 4,即使它在 64 位机器上运行。为什么它不考虑底层 HW 而是显示 8?此外,如果我的编译环境也更改为 64 位(Does a 64 bit compiler
makes sense in the first place?!),那么 int 的大小会改变吗?
是否有任何标准决定这一点?
最佳答案
取自http://en.wikipedia.org/wiki/64-bit (在 64 位数据模型下
)
有多种模型,Microsoft 决定 sizeof(int) == 4
,有些(少数)其他人没有。
从 Solaris 到 SPARC64 和 Unicos 的 HAL 计算机系统端口似乎是唯一一个 sizeof(int) == 8
。它们被称为 ILP64 和 SILP64 模型。
真正的“ war ”是针对 sizeof(long)
,Microsoft 决定使用 sizeof(long) == 4
(LLP64),而几乎所有其他人都选择 sizeof(long) == 8
(LP64).
请注意,实际上是编译器“决定”使用哪种模型,但如 wiki 中所写
Note that a programming model is a choice made on a per-compiler basis, and several can coexist on the same OS. However, the programming model chosen as the primary model for the OS API typically dominates.
关于c - 什么决定了整数的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9689049/