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

查看:26
本文介绍了如何以编程方式检测 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)

唯一的缺点是在 32 位模式下运行的 64 位计算机将注册为 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天全站免登陆