当前位置:网站首页>Simply record offsetof and container_of
Simply record offsetof and container_of
2022-08-09 16:17:00 【Yellow duck 233】
In order to prevent myself from forgetting to record the offsetof and container_of functions of the linux kernel, first define a structure casually
struct node{int a;short b;char c[5];double d;}show offsetof
//Seek the length of the member MEMBER in the structure type TYPE from the reference position#define offsetof(TYPE, MEMBER) \((size_t)&((TYPE*)0)->MEMBER)The test data is as follows

container_of
/*ptr: is the member address of a structure variabletype: is the structure typemember: is the name of the member pointed to by the ptr pointer*///Get the memory address of the structure variable from the memory address of the member in the structure variable#define container_of(ptr, type, member) ({ \const typeof( ((type*)0)->member ) *__mptr = (ptr); \(type*)( (char*)__mptr - offsetof(type, member) );})
边栏推荐
- 深刻地认识到,编译器会导致编译结果的不同
- docke安装mysql以及主从搭建(并且指定数据生成路径)
- Startup error: Caused by: org.apache.ibatis.binding.BindingException summary solution
- MySql中什么是索引?常用的索引有哪些种类?索引在什么情况下会失效?
- 注解与反射
- What are the implications of programmatic trading rules for the entire trading system?
- 编译器不同,模式不同,对结果的影响
- FilenameFilter filters filenames
- Analysis: Which method is used to build a stock quantitative trading database?
- 二叉排序树的左旋与右旋
猜你喜欢

Database multi-table link query method

pytorch从零搭建神经网络实现多分类(训练自己的数据集)

【C语言初阶】详解分支语句

怎么用VS+Qt创建新项目

xshell7连接工具下载

经典面试题 之 TCP 三次握手/ 四次挥手

内存泄露检测工具VLD(Visual Leak Detector)使用说明

ImageWatch无法显示图像

Mathematica 数据分析(简明)

What is a template engine?What are the common template engines?Introduction to common commands of thymeleaf.
随机推荐
strlen(), strcpy(), strncpy(), strcat(), strncat(), strcmp(), strncmp()函数的封装
How do quantitative investors obtain real-time market data?
[Mysql]--事务、事务的隔离级别、脏读、不可重复读、幻读解析
内存泄露检测工具VLD(Visual Leak Detector)使用说明
Servlet的生命周期
[Mysql]--Transaction, transaction isolation level, dirty read, non-repeatable read, phantom read analysis
xshell7连接工具下载
Qt控件-QTextEdit使用记录
Stock trading stylized how to understand their own trading system?
Inverted order at the beginning of the C language 】 【 string (type I like Beijing. Output Beijing. Like I)
MySql中什么是索引?常用的索引有哪些种类?索引在什么情况下会失效?
MySQL学习笔记
Qt对话框中show和exec的区别
如何通过股票量化交易接口实现盈利稳定?
浅谈一下量化交易与程序化交易
OpenCV - Matrix Operations Part 3
简单记录下offsetof和container_of
怎么才可以知道量化程序化交易是否有效?
如何灵活运用量化交易接口的优势取长补短?
redis从入门到精通