如何找到,如果机器是32位或64位 [英] how to find if the machine is 32bit or 64bit
问题描述
反正从C PROG查找是否操作系统是32位或64位模式当前正在运行。我使用的是简单的程序如下
Is there anyway from a C prog to find whether the OS is currently running in 32bit or 64bit mode. I am using a simple program as below
int main(void){
switch(sizeof(void*)){
case 4: printf("32\n");
break;
case 8: printf("64\n");
break;
}
}
这是一个正确的做法?
在会像所有的情况下,这code的工作,如果硬件是64位和操作系统是32位会是什么回报?我没有在机器的配置差异来测试这一点。
Is this a correct approach ? Would this code work in all the scenarios like, If the hardware is 64bit and the OS is 32bit what would it return ? I don't have machine to test this in diff configurations.
谢谢你的建议。
推荐答案
-
在一般情况下,32位可执行文件将无法判断它是一个64位操作系统或32位一(有些OS可能有一种方法来告诉下运行,我知道没有,但我没有搜索),64位可执行文件不会在32位操作系统下运行(如果你打折的可能性为32位操作系统模拟处理器上运行的64位操作系统...)
In general, a 32 bits executable won't be able to tell if it is running under a 64 bit OS or a 32 bit one (some OS could have a way to tell, I know of none but I haven't searched), a 64 bit executable won't run under a 32 bit OS (if you discount the possibility for the 32 bits OS to emulate a processor running a 64 bits OS...)
的sizeof()结果主要是编译时间常数,它不会返回不同的东西取决于其下运行的操作系统版本。
sizeof() result is mainly a compile time constant, it won't returns something different depending on the OS version it is running under.
你有什么想真的知道吗?
What do you want to know really?
这篇关于如何找到,如果机器是32位或64位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!