我在 C 中有以下 for 循环。我想知道为什么字大小是 64 位而不是 32 位。
#define WSIZE 8*sizeof(int)
long pcount_for(unsigned long x)
{
size_t = i;
long result = 0;
for (i = 0; i < WSIZE; i++)
{
unsigned bit = (x >> i) & 0x1;
result += bit;
}
return result;
}
最佳答案
“int”的大小取决于您的机器的体系结构。 如果您在 32 位上进行编译,则可能是 4 个字节(因此 8*4 = 32,符合您的预期)
在 AMD64 上,您必须使用 int32_t 使其变为 4 个字节。
关于c - 为什么下面的 C 代码中我的 Wordsize 是 64 位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40621528/