linux contaner of宏
来源:互联网 发布:卡盟顶部源码 编辑:程序博客网 时间:2024/05/22 04:58
参考文章 : http://blog.csdn.net/npy_lp/article/details/7010752
参考文章: http://blog.csdn.net/wangliang888888/article/details/51138664
constainer of 宏原理是:
传入三个参数,结构体某一个元素的地址ptr,结构体类型type,这个元素名字member。
ptr 赋值给内部变量_mptr,_mptr指针类型声明使用0 ,typeof取出member类型。
用member的实际地址减去member在结构体中的偏移量,就是这个结构体起始地址。
问题:
1、 为什么使用char*强转_mptr?
“这是c语言的基础知识,指针的加减对应到地址是根据指针所指的数的类型来确定的。如果MEMBER是int,而不把它的指针强制为char*,那么减去的将是4倍的地址偏移,当然是不对的。如果不用(char*)强转,那么这个 - 操作意义就不同了。返回的地址也就不同了。”
2、内核代码中双向链表是怎么回事?代码在include/linux/types.h
“我们要让链表有意义,必须使链表有信息的载体,即数据项,这是毋庸置疑的。那就让我们换个思路,既然一堆list_head已经构成一个链表,而且我们不能往list_head对象里面加入数据项,那么让这些list_head对象位于另外一个结构体的内部,作为指针域存在,这个外部结构体的其他成员作为数据项存在,是否就让链表有意义了呢。”
阅读全文
0 0
- linux contaner of宏
- History of Linux
- Introduce of Linux Security
- Driver, of WinCE & Linux
- chkconfig of linux
- Sed of UNIX/Linux
- 20 years of Linux
- The boot of Linux
- [Linux]Introduction Of Trac
- Time Management of Linux
- Index of /linux-docbook
- user management of linux
- simple command of linux
- memo of Linux C
- linux profile of env
- The State of Linux
- Cache & Buffer of Linux
- linux out of memory
- C#编写记事本程序(下)——扩展功能
- webdriver--Python
- android中getLocationInWindow 和 getLocationOnScreen的区别
- Windows10系统 DEPRECATION: The default format will switch to columns in the future解决!
- Tinyos实现温度读取汇聚收集
- linux contaner of宏
- LNMP下的Nginx的优化
- 实验3 队列
- TextView的drawable属性
- 项目整理三-Spring AOP实现日志管理
- 色彩与编码—几个小概念的综述
- centos下ifconfig没有显示eth0
- phpstudy及phpcms的安装及简单使用
- Linux系统环境变量