C语言之内核中的struct list_head 结构体
以下地址文章解释很好
http://blog.chinaunix.net/uid-27122224-id-3277511.html
对下面的结构体分析
1 struct person
2 {
3 int age;
4 int weight;
5 struct list_head list;
6 };
遍历的方法中用到的一个重要宏,这个宏可以遍历不同类型的结构体
1 /**
2 * list_entry - get the struct for this entry
3 * @ptr: the &struct list_head pointer.
4 * @type: the type of the struct this is embedded in.
5 * @member: the name of the list_struct within the struct.
6 */
7 #define list_entry(ptr, type, member) \
8 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
1 struct person *one = list_entry(pos, struct person, list);
也就是:
1 ((struct person *)((char *)(pos) - (unsigned long)(&((struct person *)0)->list)))

C语言之内核中的struct list_head 结构体的更多相关文章
- 全国计算机等级考试二级教程-C语言程序设计_第14章_结构体、共用体和用户定义类型
函数的返回值是结构体类型 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> struct ...
- Golang面向对象编程-struct(结构体)
Golang面向对象编程-struct(结构体) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.什么是面向对象编程 面向对象编程(Object Oriented Program ...
- struct socket结构体详解
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://weiguozhihui.blog.51cto.com/3060615/15852 ...
- Linux中表示“时间”的结构体和相关函数
转载于:http://blog.chinaunix.net/uid-25909722-id-2827364.html Linux中表示“时间”的结构体和相关函数 2011-09-13 17: ...
- struct ifreq结构体与ip,子网掩码,网关等信息
总结一下,今天学习的关于通过socket,ioctl来获得ip,netmask等信息,其中很多内容参照了很多网上的信息,我会一一列出的 我用的这个函数,就是下面这个函数,其中的有一些全局变量,很好懂, ...
- Objective-C中经常使用的结构体NSRange,NSPoint,NSSize(CGSize),NSRect
Objective-C中经常使用的结构体NSRange,NSPoint,NSSize(CGSize),NSRect 1 NSRange NSRange 的原型为 typedef struct _N ...
- struct timeval结构体 以及 gettimeofday()函数(转)
struct timeval结构体 转载地址:http://blog.chinaunix.net/uid-20548989-id-2533161.html 该结构体是Linux系统中定义,struct ...
- struct in_addr 结构体
struct in_addr 结构体: struct in_addr { in_addr_t s_addr; }; 表示一个32位的IPv4地址. in_addr_t一般为32位的unsigned i ...
- typedef struct与struct定义结构体
今天在定义结构体的时候发现typedef struct与struct定义结构体有一些不同之处: 结构也是一种数据类型, 能够使用结构变量, 因此, 象其他 类型的变量一样, 在使用结构变量时要先对其 ...
随机推荐
- 零基础要怎么样学习嵌入式Linux--走进嵌入式
零基础要怎么样学习嵌入式希望可以通过这一篇帖子让大家走进嵌入式,对嵌入式的学习不再那么陌生. 嵌入式Linux工程师的学习需要具备一定的C语言基础,因此面对许多朋友只是在大一或者大二学习过C(还不一定 ...
- OpenWrt编译报错:Package airfly_receiver is missing dependencies for the following libraries
今天在编译一个OpenWrt测试用例的时候出现报错 Package airfly_receiver is missing dependencies for the following librarie ...
- TDengine在浙商银行微服务监控中的实践
作者:楼永红 王轩宇|浙商银行 浙商银行股份有限公司(简称"浙商银行")是 12 家全国性股份制商业银行之一,总部设在浙江杭州,全国第13家"A+H"上市 ...
- SpringBoot之MultipartFile文件上传(6)
1.静态文件 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <ti ...
- css 按钮悬停效霓虹灯特效
css 按钮悬停效霓虹灯特效 <!DOCTYPE html> <html lang="en"> <head> <meta charset=
- 蓝图before request
方法1 @bp.before_request def test(): print("test") 方法2 def bp_before_request(): print(test) ...
- js中function (res) {}与(res) =>{}的区别
这里是引用function (res) {} 中 打印this时是undefined 打印that时是有内容的 let that = this; ...
- Failed to start connector [Connector[HTTP/1.1-8080]]
错误提示:Failed to start connector [Connector[HTTP/1.1-8080]]错误原因:Tomcat端口被占用解决方案(window下):1.cmd打开命令控制台2 ...
- 【JAVA】笔记(4)---继承;方法覆盖;多态机制;super;
继承(extends): 1.作用:为方法覆盖和多态机制做准备:使代码得到复用(节省代码量): 2.格式: class 子类 extends 父类 3.理解继承:子类继承父类,其实就相当于把父类的类体 ...
- vue3 学习笔记 (四)——vue3 setup() 高级用法
本篇文章干货较多,建议收藏! 从 vue2 升级到 vue3,vue3 是可以兼容 vue2 的,所以 vue3 可以采用 vue2 的选项式API.由于选项式API一个变量存在于多处,如果出现问题时 ...