www.cnblogs.com/ruiyqinrui

开源、架构、Linux C/C++/python AI BI 运维开发自动化运维。 春风桃李花 秋雨梧桐叶。“力尽不知热 但惜夏日长”。夏不惜,秋不获。@ruiY--秦瑞

python爬虫,C编程,嵌入式开发.hadoop大数据,桉树,onenebula云计算架构.linux运维及驱动开发.

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

include/Linux/stddef.h中macro offsetof define,list:

#define offsetof(TYPE,MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

offsetof macro对于上述示例的展开剂分析:&((struct example_struct *)0)->list表示当结构example_struct正好在地址0上时其成员list的地址,即成员位移.

traverse linked list member element;

下面使用list_entry macro遍历链表得到链表指针,再从链表指针映射回对应结构example_struct的指针,然后,对其成员priority进行操作,函数example_add_entry的功能是给链表加入新的结构成员

void example_add_entry(struct example_struct *new)

{

  struct list_head *ptr;

  struct example_struct *entry;

  //遍历链表

  for (ptr = example_list.next;ptr != &example_list;ptr = ptr->next) {

  //映射回 对应结构example_struct的指针

  entry = list_entry(ptr,struct todo_Struct,list);

  

}

}

posted on 2014-02-23 21:15  秦瑞It行程实录  阅读(177)  评论(0编辑  收藏  举报
www.cnblogs.com/ruiyqinrui