Linux内核学习中---有关#define LIST_HEAD_INIT(name) { &(name), &(name) }的问题
2015-12-30 13:30
716 查看
最近在接触内核方面的东西,遇见如下一段代码:
在网上看了很多前人工作,在这里自己做下总结。
来看数据结构体:
举例如下:
struct list_head foo = { &(foo) , &(foo)}
相当于:
struct list_head foo; foo.next = &foo; foo.prev = &foo;
另一个例子:
struct list_head test = LIST_HEAD (check); LIST_HEAD (check);
在C语言中我们使用的结构体对应实例:例如:
struct student{long int num;
char name[20];char sex;
char addr[20];
}a={10101,"Li yong tian",'M',“513477736”};
a的初始化是四项,与结构体的成员是一一对应的。而结构体中:
struct list_head foo = { &(foo) , &(foo)}
在本文中等价与
:struct list_head { struct list_head *next, *prev; } foo = { &(foo) , &(foo)};
按照成员的对应赋值就是:
struct list_head foo; foo.next = &foo; foo.prev = &foo;
最近在接触内核方面的东西,遇见如下一段代码:
<pre class="html" name="code">struct list_head { struct list_head *next, *prev; //双向链表 }; #define LIST_HEAD_INIT(name) { &(name), &(name) } #define LIST_HEAD(name) \ struct list_head name = LIST_HEAD_INIT(name) #define INIT_LIST_HEAD(ptr) do { \ (ptr)->next = (ptr); (ptr)->prev = (ptr); \ } while (0)
在网上看了很多前人工作,在这里自己做下总结。
来看数据结构体:
struct list_head { struct list_head *next, *prev; };
//宏定义如下:
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name)
举例如下:
struct list_head foo = { &(foo) , &(foo)}
相当于:
struct list_head foo; foo.next = &foo; foo.prev = &foo;
另一个例子:
struct list_head test = LIST_HEAD (check); LIST_HEAD (check);
在C语言中我们使用的结构体对应实例:例如:
struct student{long int num;
char name[20];char sex;
char addr[20];
}a={10101,"Li yong tian",'M',“513477736”};
a的初始化是四项,与结构体的成员是一一对应的。而结构体中:
struct list_head foo = { &(foo) , &(foo)}
在本文中等价与
:struct list_head { struct list_head *next, *prev; } foo = { &(foo) , &(foo)};
按照成员的对应赋值就是:
struct list_head foo; foo.next = &foo; foo.prev = &foo;
//如果我有一个定义了一个对象: <span style="font-size: 16px;">struct list_head mylist; //then LIST_HEAD(mylist); == struct list_head mylist = { &(mylist), &(mylist) } ; </span>
相关文章推荐
- 阿里云ECS服务器Linux环境下配置php服务器(一)--基础配置篇
- 鸟哥的Linux私房菜笔记
- LINUX 文件和目录 stat结构
- CentOS 创建SVN 服务器,并且自动同步到WEB 目录
- centos6.5 安装discuz记录
- Linux平台Makefile文件的编写基础篇
- CentOS系列启动流程详解
- Linux C 算法——排序
- linux ls -l 详解
- Linux系统基本知识说明和启动Linux虚拟机
- use-svn-cmd(Linux)
- install VMware tools for linux
- Linux基础
- linux恢复误删除文件-ext3grep
- linux学习考试复习笔记
- centos lvm常用命令
- linux CPU隔离和进程调度优先级设置
- Linux系统下转换文件编码的方法小结
- Android SELinux 一个编译错误
- 在 RedHat Linux 上做性能调优