Possible Duplicate:
size of int, long, etc
Does the size of an int depend on the compiler and/or processor?
What decides the sizeof an integer?
我使用的是 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-bytes
。
#include <stdio.h>
int main(void)
{
printf("sizeof(int) = %d bytes\n", (int) sizeof(int));
return 0;
}
如果我运行的是 16-
、32-
和 64-
位机器,那么这是否意味着大小integer
分别是 16-
、32-
和 64-
位?
在我的机器中,我发现 WORD_BIT
是 32
。在 64 位
机器上不应该是 64
吗?
$ getconf WORD_BIT
32
$
而且,在上述情况下,sizeof(int)
不应该是 64-bits
(8 bytes
)吗?
最佳答案
在任何 64 位 C/C++ 编译器上,指针的大小应为 8 字节,但不一定为 int 大小。
关于c++ - 64 位机器上的 sizeof(int) 应该是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10197242/