前言
在查看linux内核中,经常会看到container_of这个宏定义,第一眼看到这个宏定义中括号一层又一层,晕了。下面本文就来好好分析这个宏的具体实现。
内核版本:linux-2.6.34
container_of宏详解
container_of宏的源码定义在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 struct this is embedded in.
* @member: the name of the member within the struct.
*
*/
#define container_of(ptr, type, member) ({ \