为什么不能同时使用静态和寄存器存储类? [英] Why can't the static and register storage classes be used together?
本文介绍了为什么不能同时使用静态和寄存器存储类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以以下方式定义变量时:
When defining a variable in the following manner:
static register int a1 = 0;
我们收到错误:
error: multiple storage classes in declaration specifiers
此错误是否有任何根本原因?为什么不能既将变量存储在寄存器中,又不能仅在启动/首次调用时将其初始化? 可以将寄存器存储类附加到全局变量.<-不正确
Is there any fundamental reason for this error? Why can't a variable be both stored in a register, and also be initialized only at start up/first call? It is possible to attach the register storage class to a global variable. <- edit: not true
推荐答案
如果编译器如实地实现了您想要的功能,则它将占用CPU寄存器以占用程序的长度.这几乎是不现实的.
If a compiler implemented what you wanted faithfully then it would tie up a CPU register for the length of your program. That's hardly practical.
请记住,register
仅是建议性的.
Remember that register
is only advisory.
这篇关于为什么不能同时使用静态和寄存器存储类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文