[英]the use of double pointer (type **)ptr in __register_chrdev_region (linux kernel, 4.14.13, x86_64)
In the linux kernel (4.14.13, x86_64), the function [__register_chrdev_region()][1] declared a double pointer variable struct char_device_struct **cp;
在linux内核(4.14.13,x86_64)中,函数[__register_chrdev_region()][1]声明了一个双指针变量
struct char_device_struct **cp;
However, throughout the function, the value of cp
is never directly used, it is always used like: *cp
.然而,在整个函数中,
cp
的值从未被直接使用,它总是像这样使用: *cp
。 I don't get the point here, why not just define a pointer like: struct char_device_struct *cp
, then use the variable like cp
.我不明白这里的意思,为什么不定义一个像:
struct char_device_struct *cp
这样的指针,然后使用像cp
这样的变量。 To be more clear, for example, if the variable has been defined like: struct char_device_struct *cp
, the following piece of code from the function:更清楚地说,例如,如果变量已定义为:
struct char_device_struct *cp
,则该函数中的以下代码段:
for (cp = &chrdevs[i]; *cp; cp = &(*cp)->next)
if ((*cp)->major > major ||
((*cp)->major == major &&
(((*cp)->baseminor >= baseminor) ||
((*cp)->baseminor + (*cp)->minorct > baseminor))))
break;
could have been written like:可以这样写:
for (cp = chrdevs[i]; cp; cp = (*cp)->next)
if ((cp)->major > major ||
((cp)->major == major &&
(((cp)->baseminor >= baseminor) ||
((cp)->baseminor + (cp)->minorct > baseminor))))
break;
So I don't know why the pointer cp
is defined as a double pointer: struct char_device_struct **cp
, then it is always used by its 'dereferenced' form *cp
?所以我不知道为什么指针
cp
被定义为双指针: struct char_device_struct **cp
,那么它总是被它的“取消引用”形式*cp
? [1]: https://elixir.bootlin.com/linux/v4.14.13/source/fs/char_dev.c#L100 [1]: https : //elixir.bootlin.com/linux/v4.14.13/source/fs/char_dev.c#L100
Because several lines below there is an assignment to *cp
:因为下面的几行有一个对
*cp
的赋值:
cd->next = *cp;
*cp = cd;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.