注册数据类型变量是否有限?

时间:2021-09-17 16:49:48

i totally stucked with this question, i had heard that there are 5 to 10 variables only can declare having datatype of register. i wish to know how many register datatype variables would be declare.it is pretty to seem. but this level of understanding we required while executing a programs.otherwise we mightstuck at runtime while execution thanks for your answers in advance

我对这个问题做了彻底的研究,我听说有5到10个变量只能声明有数据类型的寄存器。我希望知道有多少注册数据类型变量将被声明。看起来很漂亮。但是在执行程序时,我们需要这样的理解。否则,我们可能会在运行时卡住,而执行时要感谢您提前给出的答案。

1).is registers(for datatypes) are vary to different types of compilers/machines??
2).how many register datatype variables could we pick ?
3).what are all these registers?(i mean cpu reg, memory reg, general purpose reg???)

1).is register (for datatypes)在不同类型的编译器/机器上是不同的?2).我们可以选择多少个注册数据类型变量?这些登记簿是什么?(我是指cpu reg,内存reg, general purpose reg??)

3 个解决方案

#1


2  

register is no more a useful keyword in C programs compiled by a recent C optimizing compiler (e.g. recent versions of GCC or Clang/LLVM).

在C程序中,寄存器不再是一个有用的关键字,它是由最近的C优化编译器编译的(例如最近版本的GCC或Clang/LLVM)。

Today, it simply means that a variable qualified as register cannot be the operand of the & unary address-of operator (notice that register is a qualifier like const or volatile are, not a data type like int).

今天,它仅仅意味着一个限定为寄存器的变量不可能是& unary address-of操作符的操作数(注意,寄存器是像const或volatile这样的限定符,而不是像int这样的数据类型)。

In the 1990s, register was then an important keyword for compilers.

在20世纪90年代,注册成为编译器的一个重要关键字。

The compiler (when optimizing) does a pretty good job about register allocation and spilling.

编译器(在优化时)在寄存器分配和溢出方面做得很好。

Try to compile your favorite C function with e.g. gcc -Wall -O2 -fverbose-asm -S; you'll get an assembly file suffixed .s and you could look inside it; the compiler is doing pretty well about register allocation.

尝试编译你最喜欢的C函数,例如gcc -Wall -O2 -fverbose -S;你会得到一个装配文件后缀。s,你可以看看里面;编译器在寄存器分配方面做得很好。

Notice that GCC provides language extensions to put a few global (or local) variables in explicit registers. This is rarely useful, and it is target processor and ABI specific.

请注意,GCC提供了语言扩展,以便在显式寄存器中添加一些全局变量(或局部变量)。这很少有用,它是目标处理器和ABI专用的。

BTW, on desktop or laptop processors, the CPU cache matters a lot more than the registers (see references and hints in this answer to another question).

顺便说一下,在台式机或笔记本电脑处理器上,CPU缓存比寄存器要重要得多(参见参考资料和提示,以回答另一个问题)。

#2


1  

In C there is no way to explicitely define variable in CPU registers. You may barely hint a compiler with register specifier, but there is no point to do it nowadays, as compilers have sophisticated optimizer, which takes care of registers allocation.

在C中,无法在CPU寄存器中明确定义变量。您可能几乎没有使用注册说明符来提示编译器,但是现在没有必要这样做,因为编译器有复杂的优化器,它负责寄存器分配。

#3


0  

do not use register. The optomizer will do a better job

不要使用寄存器。optomizer会做得更好。

#1


2  

register is no more a useful keyword in C programs compiled by a recent C optimizing compiler (e.g. recent versions of GCC or Clang/LLVM).

在C程序中,寄存器不再是一个有用的关键字,它是由最近的C优化编译器编译的(例如最近版本的GCC或Clang/LLVM)。

Today, it simply means that a variable qualified as register cannot be the operand of the & unary address-of operator (notice that register is a qualifier like const or volatile are, not a data type like int).

今天,它仅仅意味着一个限定为寄存器的变量不可能是& unary address-of操作符的操作数(注意,寄存器是像const或volatile这样的限定符,而不是像int这样的数据类型)。

In the 1990s, register was then an important keyword for compilers.

在20世纪90年代,注册成为编译器的一个重要关键字。

The compiler (when optimizing) does a pretty good job about register allocation and spilling.

编译器(在优化时)在寄存器分配和溢出方面做得很好。

Try to compile your favorite C function with e.g. gcc -Wall -O2 -fverbose-asm -S; you'll get an assembly file suffixed .s and you could look inside it; the compiler is doing pretty well about register allocation.

尝试编译你最喜欢的C函数,例如gcc -Wall -O2 -fverbose -S;你会得到一个装配文件后缀。s,你可以看看里面;编译器在寄存器分配方面做得很好。

Notice that GCC provides language extensions to put a few global (or local) variables in explicit registers. This is rarely useful, and it is target processor and ABI specific.

请注意,GCC提供了语言扩展,以便在显式寄存器中添加一些全局变量(或局部变量)。这很少有用,它是目标处理器和ABI专用的。

BTW, on desktop or laptop processors, the CPU cache matters a lot more than the registers (see references and hints in this answer to another question).

顺便说一下,在台式机或笔记本电脑处理器上,CPU缓存比寄存器要重要得多(参见参考资料和提示,以回答另一个问题)。

#2


1  

In C there is no way to explicitely define variable in CPU registers. You may barely hint a compiler with register specifier, but there is no point to do it nowadays, as compilers have sophisticated optimizer, which takes care of registers allocation.

在C中,无法在CPU寄存器中明确定义变量。您可能几乎没有使用注册说明符来提示编译器,但是现在没有必要这样做,因为编译器有复杂的优化器,它负责寄存器分配。

#3


0  

do not use register. The optomizer will do a better job

不要使用寄存器。optomizer会做得更好。