C语言标准是否指定支持全局寄存器变量 [英] Do the C language standards specify support for global register variables

查看:157
本文介绍了C语言标准是否指定支持全局寄存器变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到gcc提供了将全局变量定义为寄存器存储变量的支持。我想知道的是,这些标准是否对此支持有任何规范。 解决方案

有一种常见的误解,认为C的关键字寄存器说明硬件寄存器。这可能是该概念的起源,但在现代C中,这不是目的。 register 具有的唯一真正效果是& 在这样的野兽上是不允许的。



它们可以用编译器想要的任何方式实现,硬件寄存器,指令立即数,或堆栈上,你不知道。你所知道的是,一个寄存器变量不能与其他变量混叠。



并回答你的问题更直接地说,在文件范围内没有 register 不是C语言的一部分。如果可以的话,那将允许我们声明几乎任何基的注册const 变量,这可以用作某种全局常量

将硬件寄存器映射到特定变量是编译器提供的扩展,如gcc。作为一个扩展,Gcc的功能也适用于文件范围。但这是相当令人望而却步的,因为通常CPU没有太多的硬件寄存器可供使用。


I read that gcc provides support to define global variables as register stored variables. What I want to know is that do the standards have any specifications for this support.

解决方案

There is a common misconsception that C's keyword register talks about hardware registers. That might be the origin of that concept, but in modern C this is not the purpose. The only real effect that register has, is that the & is not allowed on such a beast.

They may be realized in any way the compiler wants, hardware registers, instruction immediates, or on the stack, you wouldn't know. What you do know is that a register variable can't alias with other variables.

And to answer your question more directly, no register in file scope is not part of the C language. If it would, that would allow us to declare register const variables of almost any base, that could serve as some sort of global constants.

Mapping hardware register to specific variables is an extension that compilers provide, e.g gcc. Gcc's feature, as an extension, also works in file scope. But that is quite prohibitive, since usually CPU's don't have many hardware registers to spare.

这篇关于C语言标准是否指定支持全局寄存器变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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