Linux内核链表管理的一些常用宏
来源:互联网 发布:unity3d安卓真机调试 编辑:程序博客网 时间:2024/06/08 19:23
对一些链表内核宏的记录备忘,小试用程序如下:
#include "stdafx.h"#include "iostream"#include <vector>#include <list>#include <typeinfo.h>#include <stdio.h>#include <stddef.h>#include <stdlib.h>using namespace std;#define offsetof(type, member) (size_t)&(((type *)0)->member)//linux//#define container_of(ptr, type, member) ({ \// const typeof(((type *) 0)->member) *__mptr = (ptr); \// (type *) ((char *) __mptr - offsetof(type, member));})//windows#define container_of(ptr, type, member) \((type*)((char*)ptr - offsetof(type, member)))#define list_entry(ptr, type, member) \ container_of(ptr, type, member)struct AAA{int i;int j;double d;AAA() { i = 0; j = 0; d = 0.0; };};struct test{int i;int j;char k;test() { i = 0; j = 0; k = 0; };};struct list_head {struct list_head *next, *prev;};struct example {int a;struct list_head list;int b;};int main(){struct AAA *pAAA;pAAA = new AAA();cout << "============ AAA ============" << endl;cout << "offsetof = " << offsetof(AAA, j) << endl;cout << "============ test ============" << endl;test temp;cout << "&temp = " << &temp << endl;cout << "&temp.j = " << &temp.j << endl;cout << "((size_t)&((test*)0)->j) = " << ((size_t)&((test*)0)->j) << endl;cout << "offsetof(test, j) = " << offsetof(test, j) << endl;cout << "============ example ============" << endl;example *ex = new example();cout << "offsetof(example, list) = " <<offsetof(example, list) << endl;cout << "list_entry(&ex->list, example, list) = "<< list_entry(&ex->list, example, list) << endl;(*(example*)container_of(&ex->list, example, list)).a = 1;(*(example*)container_of(&ex->list, example, list)).b = 3;cout << "ex->a = " << ex->a << endl;cout << "ex->b = " << ex->b << endl; return 0;}
自己记录一下,可能以后经常会用到。
阅读全文
0 0
- Linux内核链表管理的一些常用宏
- Linux内核常用的一些宏
- Linux内核常用的一些宏的收集
- 【转】Linux内核常用的一些宏的收集
- Linux内核常用的一些宏的收集(精)
- Linux内核常用的一些宏的收集
- linux内核中常用的一些宏收集
- linux内核中常用的一些宏及函数
- Linux常用的一些内核参数(调优)
- Linux常用的一些内核参数(调优)
- Linux常用的一些内核参数(调优)
- linux内核中的一些有趣的宏
- 一些Linux内核中的常用术语
- 常用的linux内核双向链表API介绍
- Linux 内核的一些算法
- Linux 内核的一些算法
- linux 内核的一些特性
- linux 的内核启动管理
- 《三》关注时生成关注者的永久二维码
- Android学习之Fragment(片段)
- PCIe驱动开发-驱动加载
- 企业级RAC+DG架构部署
- 中兴4g模块me3760拨号
- Linux内核链表管理的一些常用宏
- 智能提示帮助站长优化网站搜索
- redis详解-- 面试题
- 测试常识-术语行话
- (112)流程控制
- 如何通过curl完成一些功能
- 问题总结
- PCIe驱动开发-设备打开/关闭
- 使用websocket 实现即时消息