如何以编程方式检测64位或32位计算机? [英] How to programatically detect a 64 bit or 32 bit machine?

查看:96
本文介绍了如何以编程方式检测64位或32位计算机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白32位和64位的含义。人们似乎说64位计算机的运行速度更快-但是为什么呢?这是否意味着有64位整数而不是32位?如果是这样,是否可以编写一种程序来确定我们是在32位还是64位计算机上?

I don't understand what 32 bit and 64 bit means. It seems that people say 64 bit computers run faster - but why? Does it mean that there are 64 bit integers instead of 32? If it's something like that, is there a way to write a program to determine if we're on a 32 bit or 64 bit machine?

推荐答案

在64位计算机上,指针为8字节(64位)。在32位计算机上,它们是4字节(32位)。因此,我们可以通过指针的大小来确定要处理的内容,形式最简单:

On 64-bit machines pointers are 8 bytes (64 bits). On 32-bit machines they are 4 bytes (32 bits). Thus we can determine by the size of a pointer what we are dealing with, in it's simplest form:

#define IS_64BIT (sizeof(void *) == 8)

唯一的缺点是64位计算机以32位运行模式将注册为32位。当然,这实际上并不重要,因为就所有意图而言,一台64位计算机上的32位操作系统将是一台32位计算机。

The only drawback is that a 64 bit computer running in 32 bit mode will register as 32 bit. Of course, this isn't actually important as for all intents and purposes a 32 bit OS on a 64 bit computer will be a 32 bit computer.

这篇关于如何以编程方式检测64位或32位计算机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆