在某些(并非所有)64位linux上,int值16被截断为0,我面临着一个奇怪的问题。
- 16 becomes hex-10 and [http://qb64.net/wiki/index.php?title=%26B](http://qb64.net/wiki/index.php?title=%26B)
- though void\* is 8 byte on 64-bit OS, it can estimate only LSBs?? is this the cause?? If so why this is not easily reproducible all the time??
- or this is due to big-endian??
- Sample source code as below
样本源
int main() {
int i = 0;
void *ptr = NULL;
printf("\nsizeof - void(*) : %d , int : %d", sizeof(void*), sizeof(int));
for(i = 0; i < 20; i++) {
ptr = &i;
printf("\n%d", *((int*)ptr));
}
return 0;
}发布于 2012-10-23 17:35:55
要演示OP的注释中引用的文档中描述的问题,请将代码修改如下:
ptr = &i;
printf("\n%d", (int)ptr))若要查看地址更改,请添加以下行:
printf("\n%p", &i))并且看到两个打印的值是不同的。
所有这一切都假定sizeof(void*)与sizeof(int)一样大。
https://stackoverflow.com/questions/13023873
复制相似问题