关于container_of宏的疑问
#define container_of(ptr, type, member) ({ \
const (typeof(((type *)0)->member) *)__mptr = ptr; \
(type *)(__mptr - offsetof(type, member)); \
})
为何不能定义成这样,而非要用一个局部变量来保存ptr,有什么好处?
#define container_of(ptr, type, member) ({ \
(type *)(ptr - offsetof(type, member)); \
})
相关推荐
Linux内核宏container_of的深度剖析
1、前面说的 我在好几年前读linux 驱动代码的时候看到这个宏,百度了好久,知道怎么用了,但是对实现过程和原理还是一知半解。 container_of宏 在linux内核代码里面使用次数非常非常多,对于喜欢linux编程的同学来说,了解其实现方法,对以后看内核代码,写内核驱动的帮助都非常大,当然,我不是说了解这个就可以为所欲为了,内核博大精深,先宏观再微观去学习,不积跬步何以致千里,不要想着一口就能吃成一个胖子,我这篇文章主要剖析一下这个函数的实现原理,希望对大家学习过程中有所帮助。 android7.1/kernel/drivers/input kernel/drivers/input$
linux内核中的container_of
在内核代码中,经常见到container_of函数,它是一个宏定义,定义在include\linux\kernel.h文件中 /** * Container_of - cast a member of a structure out to the containing structure (将一个结构体的成员包含到指定的结构体中) * @ptr: the pointer to the member. (待包含的结构体成员指针) * @type: the type of the container struc
container_of:获取指向包含结构体成员的结构体的指针
名称 container_of - 获取指向包含结构成员的结构的指针 概要 #include "container_of.h" container_of(member_pointer, contains_struct, struct_member); 描述 container_of() 宏返回一个指向包含该结构体成员的结构体的指针。 如果您有一个只传递指向结构成员的指针的 API,这将非常有用。 您可以使用此宏来获取指向包含该指针的结构的指针。 member_pointer是指向container_struct成员的指针。 container_struct是包含成员的结构的类型。 struct_member是container_struct 中成员名称的文字。 返回值 指向包含此成员的结构的指针。 例子 # include < stdio> # include < stdlib
详解Linux内核中的container_of函数
大家都知道Container_of在Linux内核中是一个常用的宏,用于从包含在某个结构中的指针获得结构本身的指针,通俗地讲就是通过结构体变量中某个成员的首地址进而获得整个结构体变量的首地址。这篇文章详细的介绍了Container_of,有需要的可以参考学习。
bootstrap3中container与container_fluid外层容器的区别讲解
.container与.container_fluid是bootstrap中的两种不同类型的外层容器。这篇文章主要介绍了bootstrap3中container与container_fluid的区别,需要的朋友可以参考下


