My computer is change from 32 bits to 64 bits, and my operating system is 64 bits Windows 7. I think the pointer in 64 bits operating system should be 64 bits -- 8 bytes. However, when I use sizeof() in C++ to get the size of a point, the result is 4.
我的电脑从32位变成了64位,我的操作系统是64位的Windows 7。我认为64位操作系统中的指针应该是64位,8字节。但是,当我在c++中使用sizeof()来获得一个点的大小时,结果是4。
Why 4??
为什么4 ? ?
2 个解决方案
#1
15
Your executable is still being compiled as a 32-bit binary. Try compiling it as a 64-bit project.
您的可执行文件仍然被编译成一个32位的二进制文件。试着把它编译成一个64位的项目。
The operating system makes no difference to the internal size of a pointer if the processor is emulating the program within a 32-bit environment...
如果处理器在32位环境中模拟程序,那么操作系统对指针的内部大小没有影响……
In VS2010, head over to the configuration manager, make a new entry under 'platform', and select x64
(usually it's the only other option there)
在VS2010中,转到configuration manager,在“platform”下创建一个新条目,并选择x64(通常是这里唯一的其他选项)
EDIT: Also, make sure you're passing a void*
to the sizeof()
operator.
编辑:同时,确保您将一个void*传递给sizeof()操作符。
#2
4
Are you compiling in 64-bit mode or 32-bit mode? In Visual Studio you need to select the CPU type of the compilation, and the default might be 32-bit.
您是在64位模式还是32位模式下编译?在Visual Studio中,您需要选择编译的CPU类型,默认值可能是32位。
Also, make sure you do sizeof(void*)
.
另外,确保你做了sizeof(void*)。
#1
15
Your executable is still being compiled as a 32-bit binary. Try compiling it as a 64-bit project.
您的可执行文件仍然被编译成一个32位的二进制文件。试着把它编译成一个64位的项目。
The operating system makes no difference to the internal size of a pointer if the processor is emulating the program within a 32-bit environment...
如果处理器在32位环境中模拟程序,那么操作系统对指针的内部大小没有影响……
In VS2010, head over to the configuration manager, make a new entry under 'platform', and select x64
(usually it's the only other option there)
在VS2010中,转到configuration manager,在“platform”下创建一个新条目,并选择x64(通常是这里唯一的其他选项)
EDIT: Also, make sure you're passing a void*
to the sizeof()
operator.
编辑:同时,确保您将一个void*传递给sizeof()操作符。
#2
4
Are you compiling in 64-bit mode or 32-bit mode? In Visual Studio you need to select the CPU type of the compilation, and the default might be 32-bit.
您是在64位模式还是32位模式下编译?在Visual Studio中,您需要选择编译的CPU类型,默认值可能是32位。
Also, make sure you do sizeof(void*)
.
另外,确保你做了sizeof(void*)。