简体   繁体   English

为什么函数的参数是寄存器类型

[英]why the argument of a function are register type

sorry if my accent hurts 抱歉,如果我的口音疼

In C Programming, you can declare a function like this: dennis ritche 2nd ed page 84 在C编程中,您可以声明如下函数:dennis ritche第2版第84页

 f(register unsigned m,register long n)

Most of the books say that the default storage type of function arguments are preferably register . 大多数书都说函数参数的默认存储类型最好是register

Why so? 为什么这样? What is the need? 有什么需要?

answer followed compiler keeps them with cpu registers but 回答跟着编译器保持与cpu寄存器,但

I've not seen any difference in execution speed when using register type 使用寄存器类型时,我没有看到执行速度有任何差异

Can any one explain in detail why and where and when exactly the register is used in C Programming? 任何人都可以详细解释为什么以及何时何地在C编程中使用寄存器?

thanks 谢谢

I'd be interested in seeing which books say this. 我有兴趣看看哪些书说这个。

To be honest, at this point the state of compiler technology, there is almost never any use to declaring something with a register modifier. 说实话,在这一点上编译器技术的状态,几乎从来没有任何用于声明register修饰符的东西。 In fact, many compilers will simply throw this out, and do whatever they want. 事实上,许多编译器只会抛弃它,并做任何他们想做的事情。 The point is that this varies so much across architectures, compilers, and is also affected by what kinds of other optimization are done by the compiler. 关键在于,这在架构,编译器之间变化很大,并且还受到编译器完成的其他优化的影响。 So, the choice of whether or not to store something in a register is a choice better left to the compiler and the use of the register modifier is usually considered an archaic antipattern. 因此,选择是否将某些内容存储在寄存器中是最好留给编译器的选择,并且使用register修饰符通常被认为是一种古老的反模式。

EDIT: I incorrectly remembered register was a qualifier (which doesn't line up with the use of a type qualifier anyway, so I should have known), fixed... 编辑:我错误地记得register是一个限定符(无论如何都不符合使用类型限定符,所以我应该知道),修复...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么可以将另一种类型的参数传递给函数? - Why is it possible to pass an argument of another type to a function? 为什么函数`memchr()` 使用`int` 作为`char` 类型的参数? - Why does the function `memchr()` use `int` for the argument of `char` type? 为什么将具有不同参数类型的函数存储到带有void *参数UB的函数指针? - Why is storing a function with different argument type to function pointer with void* argument UB? 为什么将函数作为函数的参数传递? - why pass as argument of a function a function? 检查函数参数的类型,C - Checking type of function argument, C 参数类型不兼容且在此函数中未初始化 - Incompatible type for argument and uninitialised in this function 让编译器在调用 function 之前忽略设置参数寄存器 - Have compiler ignoring setting an argument register before calling function 为什么将函数参数标记为 volatile - Why mark function argument as volatile 为什么在作为参数传递给具有数组类型参数的函数之前需要转换指向数组的指针? - Why does a pointer to array need to be cast before being passed as parameter to a function with array type argument? 当我将其用作函数返回类型或参数时,为什么要输入typedef枚举 - Why should I typedef enum when I use it as function return type or argument
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM