您的位置:首页 > 其它

内核双向链表list.h中的list_entry

2011-12-31 17:31 351 查看
内核双向链表list.h中的list_entry定义:

#define list_entry(ptr, type, member)      container_of(ptr, type, member)

程序注释为:

/**

 * list_entry - get the struct for this entry

 * @ptr:    the &struct list_head pointer.

 * @type:    the type of the struct this is embedded in.

 * @member:    the name of the list_struct within the struct.

 */

刚开始没有理解。

现在明白,注释的意思是从一个实体中得到它的结构体。

#define container_of(ptr, type, member) ({const typeof( ((type *)0)->member ) *__mptr = (ptr); (type *)( (char *)__mptr - offsetof(type,member) );})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  list struct