本文介绍了什么决定整数的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

sizeof(int) 在我的 Dev Cpp 上显示 4,即使它在 64 位机器上运行.为什么它不考虑底层硬件并显示 8 呢?另外,如果我的编译环境也更改为 64 位(64 位编译器 是否首先有意义?!),那么 int 的大小会改变吗?

sizeof(int) shows 4 on my Dev Cpp even though its running on a 64 bit machine. Why doesn't it consider the underlying HW and show 8 instead? Also, if I compiling environment also changes to 64 bit ( Does a 64 bit compiler makes sense in the first place?! ), would size of int change then?

是否有任何标准来决定这一点?

Are there any standards which decide this?

推荐答案

摘自 http://en.wikipedia.org/wiki/64-bit(在64-bit data models下)

有多种模型,微软决定 sizeof(int) == 4,有些(少数)其他人没有.

There are various models, Microsoft decided that sizeof(int) == 4, some (a few) others didn't.

Solaris 到 SPARC64 和 Unicos 的 HAL 计算机系统端口似乎是 sizeof(int) == 8 的唯一端口.它们被称为 ILP64 和 SILP64 模型.

HAL Computer Systems port of Solaris to SPARC64 and Unicos seem to be the only ones where sizeof(int) == 8. They are called ILP64 and SILP64 models.

真正的战争"是针对 sizeof(long),微软决定使用 sizeof(long) == 4 (LLP64) 而几乎所有人都决定使用 sizeof(long) == 4 (LLP64)代码>sizeof(long) == 8 (LP64).

The true "war" was for sizeof(long), where Microsoft decided for sizeof(long) == 4 (LLP64) while nearly everyone else decided for sizeof(long) == 8 (LP64).

请注意,实际上是由编译器决定"使用哪个模型,但正如 wiki 中所写的那样

Note that in truth it's the compiler that "decides" which model to use, but as written in the wiki

请注意,编程模型是在每个编译器的基础上做出的选择,并且多个模型可以在同一个操作系统上共存.但是,选择作为 OS API 主要模型的编程模型通常占主导地位.

这篇关于什么决定整数的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 15:43