【方法一】
使用宏定义,判断long long类型的位数。
#include <iostream>
using namespace std;
#define IS_64bit() (sizeof(long) == 8)
#define IS_32bit() (sizeof(long) == 4)
void main(void)
{
cout<<IS_32bit()<<endl;
cout<<IS_64bit()<<endl;
}
using namespace std;
#define IS_64bit() (sizeof(long) == 8)
#define IS_32bit() (sizeof(long) == 4)
void main(void)
{
cout<<IS_32bit()<<endl;
cout<<IS_64bit()<<endl;
}
【方法二】
判断一个指针的大小。sizeof(ptr)。
因为指针的位数代表了CPU所能寻址的范围,所以也能判断出来。