什么应该是一个64位计算机上的sizeof(int)的? [英] What should be the sizeof(int) on a 64-bit machine?
问题描述
可能重复:结果
中的int,long等结果大小
<一href=\"http://stackoverflow.com/questions/2331751/does-the-size-of-an-int-depend-on-the-compiler-and-or-processor\">Does int的大小取决于编译器和/或处理器上?结果
什么决定的sizeof整数?
我使用的是 64位
的机器。
$ uname -m
x86_64
$ file /usr/bin/file
/usr/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, stripped
$
当我跑到下面的程序,我得到了的sizeof(INT)
为 4字节
。
When I ran the following program, I got the sizeof(int)
as 4-bytes
.
#include <stdio.h>
int main(void)
{
printf("sizeof(int) = %d bytes\n", (int) sizeof(int));
return 0;
}
如果我运行一个 16 -
, 32 -
和 64
位的机器,那么不就意味着一个整数
的大小为 16 -
, 32 -
和 64 - ?
位分别为
If I'm running a 16-
, 32-
and 64-
bit machine, then doesn't it mean that the size of an integer
is 16-
, 32-
and 64-
bit respectively?
在我的机器上,我找到了 WORD_BIT
是 32
。难道不应该是 64
在 64位
机器?
In my machine, I found the WORD_BIT
is 32
. Shouldn't it be 64
on a 64-bit
machine?
$ getconf WORD_BIT
32
$
和,不应该在的sizeof(INT)
是 64位
( 8字节
),在上述情况下?
And, shouldn't the sizeof(int)
be 64-bits
(8 bytes
) in the above case?
推荐答案
没有到; 64位的机器可以意味着很多东西,但通常是指CPU有寄存器那么大。所述的sizeof一个类型由编译器,它不必有任何与实际的硬件做(尽管它通常那样)确定;实际上,在同一计算机上的不同的编译器可以为这些具有不同的值。
Doesn't have to be; "64-bit machine" can mean many things, but typically means that the CPU has registers that big. The sizeof a type is determined by the compiler, which doesn't have to have anything to do with the actual hardware (though it typically does); in fact, different compilers on the same machine can have different values for these.
这篇关于什么应该是一个64位计算机上的sizeof(int)的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!