c++ - 64 位机器上的 sizeof(int) 应该是多少?

标签 c++ c sizeof

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_BIT32。在 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/

相关文章:

c++ - 初始化列表中的序列点警告

c++ - 从头开始构建一个 xml 树 - pugixml C++

比较两个字符串之间的元素

c - 指针类型与嵌套指针不兼容

c++ - Linux gcc 链接问题

arrays - C 中 sizeof() 运算符中 "comma"运算符的行为

c++ - Stroustrup : For C++, 如何安装 FLTK 库?

c++ - SDL - C++ 中 LoopTimer 的 FPS 问题

c - 指向数组的指针 - C 编程

c - 链表中的节点是单独的结构还是同一结构的一部分?