c - 什么决定了整数的大小?

标签 c compiler-construction 64-bit sizeof

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/

相关文章:

c - 为什么 ntdll.dll 导出 NtXXX 和 ZwXXX 而不是仅导出 NtXXX?

c++ - C++ 编译器是否针对不同平台(Linux、Windows 等)多次编写?

c++ - 为什么 C++ 编译器不消除 new 返回的指针的空检查?

memory - 编译器如何在内存中布局代码

java - 如果其他 jar 是用 64 位编译的,那么用 32 位 java 构建安全吗?

linux - 带 vs 不带 $ 的 x64 汇编文字

c - memcpy 3D 数组的列到 1D 数组

c - 通过scanf输入字符串

c - 为什么我的动态字符串数组会泄漏?

c++ - 使用C++ Makefile.win检测Windows的i386 vs x64?