是否还在使用 register 关键字? [英] Is the register keyword still used?

查看:27
本文介绍了是否还在使用 register 关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚在 C++ 中遇到 register 关键字,我想知道这似乎是个好主意(将某些变量保存在寄存器中)编译器是否会默认执行此操作?

Just came across the register keyword in C++ and I wondered as this seems a good idea (keeping certain variables in a register) surely the compiler does this by default?

所以我想知道这个关键字还在使用吗?

So I wondered is this keyword still used?

推荐答案

大多数实现只是忽略 register 关键字(除非它强加了语法或语义错误).

Most implementations just ignore the register keyword (unless it imposes a syntactical or semantical error).

该标准也没有说任何东西都必须保存在寄存器中;只是它暗示了该变量将经常使用的实现.它的使用甚至已被弃用.

The standard also doesn't say that anything must be kept in a register; merely that it's a hint to the implementation that the variable is going to be used very often. Its use is even deprecated.

3) 寄存器说明符是对实现的提示,即如此声明的变量将被大量使用.[ 注意:可以忽略提示,并且在大多数实现中,如果采用变量的地址,它将被忽略.这种用法已被弃用(见 D.2).— 尾注 ]

7.1.1 Storage class specifiers [dcl.stc]

3) A register specifier is a hint to the implementation that the variable so declared will be heavily used. [ Note: The hint can be ignored and in most implementations it will be ignored if the address of the variable is taken. This use is deprecated (see D.2). — end note ]

这篇关于是否还在使用 register 关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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