实施可以考虑作为提示语句的实际? [英] Can an implementation consider hints as actual statements?

查看:111
本文介绍了实施可以考虑作为提示语句的实际?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C中,注册存储预选赛是一个的提示的到,这样的标识应该尽可能快地(例如存储在被访问的实现CPU寄存器)。

In C, the register storage qualifier is an hint to the implementation that such identifier should be accessed as fast as possible (e.g. stored in a CPU register).

§6.7.1
  与存储类说明注册一个对象标识符的声明表明,访问对象是尽可能快。到这样的建议是有效的程度是实现定义的。

§6.7.1 A declaration of an identifier for an object with storage-class specifier register suggests that access to the object be as fast as possible. The extent to which such suggestions are effective is implementation-defined.

§6.7.3的用途限制条件的(如寄存器存储
  类)是促进优化[...]

§6.7.3 The intended use of the restrict qualifier (like the register storage class) is to promote optimization [...]

不过,我听说实现(在嵌入式系统中专门找到),其中注册具有较强的意义:它是一个的命令的和编译器应当将合格标识在寄存器中。

However, I've heard about implementations (specifically found in embedded systems) where register has a stronger meaning: it is a command and the compiler shall place the qualified identifier in a register.

因此​​,是一个实现的允许的遵循这一行为,因而被视为符合标准的?什么会允许呢?

So, is an implementation allowed to follow that behavior and thus considered as standard-compliant? What would permit that?

因为我发现,被有义务把该对象在寄存器中,我提出这个问题不再是建议,因为规定的标准;他们的冲突,换句话说。

I'm raising this question because I find that being obligated to place that object in a register is no longer suggestion, as mandated by the Standard; they conflict, in other words.

推荐答案

正如你说的,标准说在何种程度上这些建议是有效的是实现定义的。

As you say, the standard says "The extent to which such suggestions are effective is implementation-defined."

这给出了实施免费范围做是忽略的建议,动天地,以实现任何事情。其中选择接受注册符规定必须使用的寄存器的肯定是不矛盾的标准,并且也没有实现它只是使关于寄存器的展示位置作出自己的决定的实施不管符的。

That gives the implementation free range to do anything from ignoring the suggestion to moving heaven and earth to implement it. An implementation which chooses to accept the register specifier as requiring the use of a register is certainly not contradicting the standard, and nor is an implementation which just makes its own decisions about register placements regardless of specifiers.

一件事的实现不应该做的是拒绝编译程序,因为它需要溅出注册 - 至少,到限制规定在与教派; 5.2.4.1的翻译限制的 - 但没有从发出警告停止编译器。 (从没有发布任何事情的警告停止编译器;它很常见的编译器警告被认为危险的完全合法的结构)

The one thing the implementation should not do is refuse to compile a program because it would need to spill a register -- at least, up to the limits specified in §5.2.4.1 Translation limits -- but nothing stops the compiler from issuing a warning. (Nothing stops the compiler from issuing warnings about anything; it's common for compilers to warn about perfectly legal constructs which are considered dangerous.)

编辑:李自成5.2.4.1,在我看来,一个实现实际上可以拒绝编译它认为有太多的注册符,由于限制子句只结合实施,以便能够翻译和执行一个程序,其中包括(例如)511的标识符与块范围在一个块中声明的,而不是它这样做的任何程序。所以,就我所看到的,编译器可能会坚持认为,至少一个程序,它打这个限制没有任何的注册规范。

Rereading 5.2.4.1, it seems to me that an implementation could actually refuse to compile a program which it considers to have too many register specifiers, since the limits clause only binds the implementation to be able to translate and execute "one program" which includes (for example) "511 identifiers with block scope declared in one block", and not any program which does so. So as far as I can see, the compiler could insist that the "at least one program" which hits that limit not have any register specifications.

注意:并非所有的CPU必须在这个词的常识寄存器,但该标准实际上并没有说有关硬件什么。它只是说,注册说明传达程序员的愿望,使访问对象是尽可能快。此外,编译器的尝试,以满足这一愿望实际上并不具有优化访问对象;这是不是违反了优化的尝试失败优化标准。

Note: Not all CPUs have registers in the common sense of the word, but the standard does not actually say anything about hardware. It simply says that the register specifier communicates the programmer's desire to make "access to the object be as fast as possible". Moreover, the compiler's attempt to satisfy that desire does not actually have to optimize access to the object; it's not a violation of the standard for optimization attempts to fail to optimize.

这篇关于实施可以考虑作为提示语句的实际?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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