替换已弃用的寄存器关键字C ++ 11 [英] Replacement for deprecated register keyword C++ 11

查看:329
本文介绍了替换已弃用的寄存器关键字C ++ 11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读(此处),注册表关键字在C ++ 11中已弃用。因此,在较新版本的标准中是否存在与此存储类说明符相同的内容,或者是由编译器负责?

I have read (here, for example) that the register keyword is deprecated in C++ 11. As such, is there an equivalent to this storage-class specifier in the newer versions of the standard, or is it taken care by the compiler?

推荐答案

我们可以在 www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4193.html#809\">缺陷报告809:弃用注册表关键字,说明(强调我的):

We can find the rationale for depreciating register in defect report 809: Deprecation of the register keyword which says (emphasis mine):


register关键字的功能非常少,不提供
通常被忽略
。它应该是
在这个版本的标准中弃用,释放保留名称
在未来的标准中使用,很像汽车已被重用这个
时间同样无用。

The register keyword serves very little function, offering no more than a hint that a note says is typically ignored. It should be deprecated in this version of the standard, freeing the reserved name up for use in a future standard, much like auto has been re-used this time around for being similarly useless.

删除C ++ 17的注册表 在Lenexa会议上批准,但仍保留供将来使用。

The removal of register for C++17 was approved in the Lenexa meeting but it is still reserved for future use.


register关键字在2011 C ++标准中已弃用,
效果已在语言
中隐含。它仍保留为标准未来使用的
,是删除其残留的
规范的时间。

The register keyword was deprecated in the 2011 C++ standard, as its effect was already implicit in the language. It remains reserved for future use by the standard, and is time to remove its vestigial specification.

由于 as-if规则,编译器只需模拟 observable行为,因此优化器可以通过 as-if规则选择在寄存器中保存变量,如果它不会影响可观察的行为,并且可能在大多数情况下会做出更好的选择,因为它通常有更多信息。

Because of the as-if rule the compiler only has to emulate the observable behavior of the program and therefore the optimizer can via the as-if rule choose to keep a variable in a register if it won't effect observable behavior and presumably will in most cases make better choices since it usually has more information.

有关参考,请参阅 gcc 邮件列表中的registerC关键字的角色?回复在帖子中说:

For reference also see role of "register" C keyword? from the gcc mailing list, one of the replies in the thread says:


register关键字在gcc中影响了寄存器分配

I don't think the "register" keyword ever affected register allocation in gcc. For that you have to go back to compilers of the 1970s.

注册关键字在gcc
扩展中仍然有用处:gcc uses它与asm组合实现寄存器
变量。

The register keyword does still have a use, though, in a gcc extension: gcc uses it in combination with asm to implement register variables.

这篇关于替换已弃用的寄存器关键字C ++ 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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