内核分析阅读笔记

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行程实录 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/ruiy/p/linked.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值