C中的32或64位处理器信息 [英] 32 or 64 bit processor info in C

查看:93
本文介绍了C中的32或64位处理器信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


如果处理器是32 b / b
或64位,C中是否有办法在运行时获取信息?


干杯,

Broeisi

Hello,

Is there a way in C to get information at runtime if a processor is 32
or 64 bit?

Cheers,

Broeisi

推荐答案

文章< ; 11 ********************** @ b75g2000hsg.googlegroups .com> ;,

broeisi< br ****** *@gmail.com写道:
In article <11**********************@b75g2000hsg.googlegroups .com>,
broeisi <br*******@gmail.comwrote:

>如果处理器是32位还是64位,C中是否有办法在运行时获取信息?
>Is there a way in C to get information at runtime if a processor is 32
or 64 bit?



不,不在标准C中。


首先,您必须准确定义它对处理器意味着什么

为32或64位,这是至少有4种不同的b $ b正确(但相互矛盾)的答案。

-

那时候我很年轻,但我也很沮丧。

- 克里斯托弗牧师

No, not in standard C.

First you''d have to define exactly what it means for a processor
to be 32 or 64 bit, which is something that has at least 4 different
correct (but contradictory) answers.
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest





10月10日,21:07,罗伯... @ ibd.nrc-cnrc.gc.ca(Walter Roberson)写道:


On 10 apr, 21:07, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote:

文章< 1176230815.876762.147 ... @ b75g2000hsg.googlegroups .com>,


broeisi< broeis ... @ gmail.comwrote:
In article <1176230815.876762.147...@b75g2000hsg.googlegroups .com>,

broeisi <broeis...@gmail.comwrote:

如果处理器是32 b / b $ b或64位,C在运行时是否有办法获取信息?
Is there a way in C to get information at runtime if a processor is 32
or 64 bit?



不,不在标准C中。


首先,您必须准确定义它对处理器意味着什么

为32或64位,这是至少有4种不同的b $ b正确(但相互矛盾)的答案。

-

当时我还很年轻,但我也很朦胧。

- Christopher Priest


No, not in standard C.

First you''d have to define exactly what it means for a processor
to be 32 or 64 bit, which is something that has at least 4 different
correct (but contradictory) answers.
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest



非常感谢你回答克里斯托弗。

但是像linux或windows这样的操作系统如何知道它安装在一台32或64位的

计算机上处理器?


Thank you very much for you answer Christopher.
But how does an OS like linux or windows know that it''s installed on a
computer with a 32 or 64 bit processor?


在文章< 11 ********************** @ b75g2000hsg.googlegroups .com> ;,

broeisi< br ******* @ gmail.comwrote:
In article <11**********************@b75g2000hsg.googlegroups .com>,
broeisi <br*******@gmail.comwrote:

> 10月10日,21日: 07,rober ... @ ibd.nrc-cnrc.gc.ca(Walter Roberson)写道:
>On 10 apr, 21:07, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote:

>在文章< 1176230815.876762.147 ... @ b75g2000hsg.go oglegroups .com>,
>In article <1176230815.876762.147...@b75g2000hsg.googlegroups .com>,


> broeisi< broeis ... @ gmail.comwrote :
>broeisi <broeis...@gmail.comwrote:

>如果处理器是32位还是64位,C中是否有办法在运行时获取信息?
>Is there a way in C to get information at runtime if a processor is 32
or 64 bit?


>不,不在标准C.
>No, not in standard C.


>首先,您必须准确定义处理器的含义
32或64位,
>First you''d have to define exactly what it means for a processor
to be 32 or 64 bit,


>但是像linux或windows这样的操作系统如何知道它安装在<带32或64位处理器的计算机?
>But how does an OS like linux or windows know that it''s installed on a
computer with a 32 or 64 bit processor?



操作系统是实现的,所以允许做的事情

C未定义或未指定。

当编译操作系统时,它已经内置了某些硬件假设

- 假设,例如处理器的机器语言是什么?
。操作系统可以访问处理器状态

C未定义的寄存器;状态寄存器甚至可能需要特殊的指令才能访问。由于操作系统知道它运行的是什么样的处理器(通常),它知道如何解释状态寄存器以确定处理器能力

(例如是否有硬件音频支持说明。)


有些人定义32位或64位处理器。根据支持的

指令。这不是最好的定义,

但是,因为你还需要知道有多少数据

位可以在数据总线上一次传输:特定的

处理器型号可能支持几种不同的数据总线宽度

并隐藏用户的所有细节。处理器可能

有一条指令将两个32位数相乘并生成
a 64位数,但它可能会将这64位转移到内存中

一次16位。你定义32位还是64位?通过指令

设置,或者你用硬件实际做什么来定义它?

注意:一般来说,处理器会读取一些硬连线上的cpu引脚

主板为了弄清楚总线宽度。


C语言本身不提供直接访问硬件

的机制,几乎没有任何限制关于

硬件如何运作。 C语言标准为用户设施提供了写入便携式代码的
,并将便携式

设施的详细信息留给了实施。如果你有一些东西,那么
取决于处理器是32位还是64位(不管是什么,b $ b可能意味着什么),那么你几乎肯定会有一些东西

不便携C.

-

编程是在你忙于制定其他计划的时候发生的事情。

The OS is implementation, and so is allowed to do things that
C leaves undefined or unspecified.

When an OS is compiled, it already has certain hardware assumptions
built into it -- assumptions such as what the machine language of
the processor looks like. OSes may have access to processor status
registers that C does not define; the status registers may even
require special instructions to access. Since the OS knows what
kind of processor (generally) it is running on, it knows how to
interpret the status registers to determine processor capabilities
(such as whether there is hardware audio support instructions.)

Some people define "32 or 64 bit processor" according to the
instructions that are supported. That''s not the best of definitions,
though, because you also need to know things like how many data
bits may be transfered at a time on the databus: a particular
processor model might support several different databus widths
and hide all the details from the users. A processor might
have an instruction to multiply two 32 bit numbers and produce
a 64 bit number, but it might transfer those 64 bits to memory
16 bits at a time. Do you define "32 or 64 bit" by the instruction
set, or do you define it by what the hardware actually does?
Note: generally, the processor reads some cpu pins hardwired on the
motherboard in order to figure out bus widths.

The C language itself provides no mechanisms to access hardware
directly, and provides almost no restrictions on how the
hardware operates. The C langauge standard provide user facilities
to write -portable- code, and leaves the details of the portable
facilties to the implementation. If you have something that
depends on whether the processor is 32 or 64 bit (whatever that
might mean), then you have something that is almost certainly
not portable C.
--
Programming is what happens while you''re busy making other plans.


这篇关于C中的32或64位处理器信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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