Linux内核中 container_of()函数

参考:https://www.linuxidc.com/Linux/2016-08/134481.htm

container_of(ptr, type, member)

参数:

ptr:指针

type:类型

member:成员

看一个例子:

Struct test
        {
                int i;
                int j;
                char k;
        };
        Struct test temp;

现在呢如果我想通过temp.j的地址找到temp的首地址就可以使用container_of(&temp.j,struct test,j);

扫描二维码关注公众号,回复: 2900838 查看本文章

现在我们知道container_of()的作用就是通过一个结构变量中一个成员的地址找到这个结构体变量的首地址

通俗地讲:通过孩子,找到父亲(根据结构体成员,获取结构体指针的函数)

猜你喜欢

转载自blog.csdn.net/xiaodingqq/article/details/81987709