可以GCC / g ++的告诉我,当它忽略了我的注册? [英] Can gcc/g++ tell me when it ignores my register?
问题描述
在编译C / C ++ codeS使用gcc / g ++的,如果它忽略了我的寄存器,可以将它告诉我吗?
例如,在此code
When compiling C/C++ codes using gcc/g++, if it ignores my register, can it tell me? For example, in this code
int main()
{
register int j;
int k;
for(k = 0; k < 1000; k++)
for(j = 0; j < 32000; j++)
;
return 0;
}
Ĵ将被用作寄存器,但是在这个code
j will be used as register, but in this code
int main()
{
register int j;
int k;
for(k = 0; k < 1000; k++)
for(j = 0; j < 32000; j++)
;
int * a = &j;
return 0;
}
Ĵ将是一个正常的变量。
它可以告诉我,我使用的寄存器变量是否真的存储在CPU寄存器?
j will be a normal variable. Can it tell me whether a variable I used register is really stored in a CPU register?
推荐答案
您可以相当假定GCC忽略注册
关键字也许除了在 - O0
。但是,它不应该有所作为这种或那种方式,如果你是在这样的深度,你应该已经阅读组装code。
You can fairly assume that GCC ignores the register
keyword except perhaps at -O0
. However, it shouldn't make a difference one way or another, and if you are in such depth, you should already be reading the assembly code.
下面是关于这一主题的信息线索:的http:// GCC .gnu.org /毫升/ GCC / 2010-05 / msg00098.html 。早在过去,注册
的确有助于编译器将变量分配到寄存器,但今天寄存器分配可以自动优化来实现,而不提示。关键字并继续为用C两个目的:
Here is an informative thread on this topic: http://gcc.gnu.org/ml/gcc/2010-05/msg00098.html . Back in the old days, register
indeed helped compilers to allocate a variable into registers, but today register allocation can be accomplished optimally, automatically, without hints. The keyword does continue to serve two purposes in C:
- 在C中,prevents你采取变量的地址。因为寄存器没有地址,这个限制可以帮助一个简单的C编译器。 (简单的C ++编译器不存在。)
- A
注册
对象不能声明限制
。因为限制
涉及的地址,他们的交集是没有意义的。 (C ++还没有限制
,反正,这个规则是有点微不足道。)
- In C, it prevents you from taking the address of a variable. Since registers don't have addresses, this restriction can help a simple C compiler. (Simple C++ compilers don't exist.)
- A
register
object cannot be declaredrestrict
. Becauserestrict
pertains to addresses, their intersection is pointless. (C++ does not yet haverestrict
, and anyway, this rule is a bit trivial.)
有关C ++中,关键字一直以来C ++ 11 pcated德$ P $和的从原定的2017年标准修订提出了去除。
For C++, the keyword has been deprecated since C++11 and proposed for removal from the standard revision scheduled for 2017.
一些编译器使用了注册
的参数声明确定的函数调用约定,与ABI允许混合stack-和基于寄存器的参数。这似乎是不合格的,它往往与像扩展语法寄存器(A1)
来发生了,我不知道任何这样的编译器是否仍在使用中。
Some compilers have used register
on parameter declarations to determine the calling convention of functions, with the ABI allowing mixed stack- and register-based parameters. This seems to be nonconforming, it tends to occur with extended syntax like register("A1")
, and I don't know whether any such compiler is still in use.
这篇关于可以GCC / g ++的告诉我,当它忽略了我的注册?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!