在内存中,指针不同于一般变量,存的是变量的地址,在同一架构下地址长度都是相同的,是cpu的最大寻址内存空间,所以不同类型的指针长度都一样。
在32位机器上,指针占4个字节。在64位机器上,占8个字节。
===================================================
在vc6上验证指针在内存中的字节数:
printf("%d\n",sizeof(char*));
printf("%d\n",sizeof(int*));
printf("%d\n",sizeof(float*));
printf("%d\n",sizeof(double*));
结果:
4
4
4
4
我的操作系统是x64,应该全是 8 才对。查阅了很多资料,最后得知vc6是在32位系统下执行程序的。
下面是检验方法。
1. 检测代码:
(在vc6中直接复制运行)
#include <stdio.h>
#include <windows.h>
#include <tchar.h>
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
LPFN_ISWOW64PROCESS fnIsWow64Process;
BOOL IsWow64()
{
BOOL bIsWow64 = FALSE;
//IsWow64Process is not available on all supported versions of Windows.
//Use GetModuleHandle to get a handle to the DLL that contains the function
//and GetProcAddress to get a pointer to the function if available.
fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(
GetModuleHandle(TEXT("kernel32")),"IsWow64Process");
if(NULL != fnIsWow64Process)
{
if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
{
//handle error
}
}
return bIsWow64;
}
int main( void )
{
if(IsWow64())
_tprintf(TEXT("The process is running under WOW64.\n"));
else
_tprintf(TEXT("The process is not running under WOW64.\n"));
return 0;
}
(转自 https://docs.microsoft.com/zh-cn/windows/win32/api/wow64apiset/nf-wow64apiset-iswow64process?redirectedfrom=MSDN
2.判断
结果
The process is running under WOW64.
WOW64 什么意思?
MSDN上关于IsWow64Process函数的解释:“Determines whether the specified process is running under WOW64.”
这里的WOW64是Windows上提供的一种机制,用来在64位系统上运行32位进程。(重点!)
如果当前进程运行在WOW64,意味着当前进程是一个32位进程并运行在支持WOW64的64位系统上。
(转自https://www.jianshu.com/p/b90fc847afb3
3.结论
虽然操作系统是64位的,但是vc6是运行的32位进程。
因此在vc6 IDE下,相当于是在32位系统下运行。