[英]Why size of void pointer is 4 on Windows 64-bit platform
I have the following program that prints 4. I am running this program on Windows 7 64-bit. 我有以下程序打印4.我在Windows 7 64位上运行此程序。 Shouldn't it print 8 for 64-bit platform?
不应该为64位平台打印8? Thanks in advance.
提前致谢。
#include <stdio.h>
void main()
{
printf("%d", sizeof(void*));
}
When you use a compiled language such as C, the size of the pointer is not determined by the platform on which you are running your code: it depends only on the platform for which you have compiled your code. 当您使用诸如C的编译语言时,指针的大小不是由运行代码的平台决定的:它仅取决于您编译代码的平台。
Windows 7 64-bit can run code compiled for 32-bit platforms. Windows 7 64位可以运行为32位平台编译的代码。 Judging by the output of your program, it appears that your code has been compiled for Win-32.
根据程序的输出判断,您的代码似乎已经为Win-32编译。
In Visual Studio 2010, to to the properties page of your C/C++ project, and make sure that Active (x64)
is selected in the "Platform" drop-down (it's Win32 by default). 在Visual Studio 2010中,转到C / C ++项目的属性页,并确保在“平台”下拉列表中选择了
Active (x64)
(默认情况下为Win32)。 If x64
is not available in the dropdown, click [Configuration Manager...]
, and choose x64
for the platform of your project. 如果下拉列表中没有
x64
,请单击[Configuration Manager...]
,然后为项目平台选择x64
。 If a "Copy from..." dialog opens, click [OK]
to dismiss it. 如果打开“从...复制”对话框,请单击
[OK]
将其关闭。 The program should run in 64-bit mode after a recompile. 重新编译后,程序应以64位模式运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.