当前位置:网站首页>简单记录下offsetof和container_of
简单记录下offsetof和container_of
2022-08-09 14:53:00 【黄小鸭233】
为了防止自己忘记记录一下linux内核的offsetof 和 container_of两个函数,先随便定义一个结构体
struct node
{
int a;
short b;
char c[5];
double d;
}显示offsetof
//求结构体类型TYPE中成员MEMBER距离基准位置的长度
#define offsetof(TYPE, MEMBER) \
((size_t)&((TYPE*)0)->MEMBER)测试数据如下

container_of
/*
ptr: 是一个结构体变量的成员地址
type: 是结构体类型
member: 是ptr指针指向的成员名
*/
//由结构体变量中成员的内存地址获取结构体变量的内存地址
#define container_of(ptr, type, member) ({ \
const typeof( ((type*)0)->member ) *__mptr = (ptr); \
(type*)( (char*)__mptr - offsetof(type, member) );})
边栏推荐
- In the process of quantitative trading, retail investors can do this
- 写在光学之前--振动和波
- Technology Sharing | How to Handle Header Cookies in Interface Automation Testing
- What do professional quantitative traders think about quantitative trading?
- OpenCV - 图像模板匹配 matchTemplate
- 常微分方程的幂级数解法
- 对于程序化交易,重在预测还是重在对策呢?
- Regular Expressions for Shell Programming
- 双摄像头系列原理深度剖析【转载】
- 流程控制学习
猜你喜欢
随机推荐
股票程序化交易如何理解自己的交易系统?
A Preliminary Study on Baidu Open Source e-chart
OpenSSF's open source software risk assessment tool: Scorecards
What is the difference between the four common resistors?
MySQL 原理与优化:Limit 查询优化
量子力学初步
How to use and execute quantitative programmatic trading?
百度地图——鹰眼轨迹服务
Mysql two engines comparison
分析:通过哪种方法来建立股票量化交易数据库?
FilenameFilter filters filenames
EasyExcel的应用
How to achieve stable profit through the stock quantitative trading interface?
My MySQL database was attacked and deleted for ransom, forcing me to use all my might to recover data
贝塞尔函数
OpenCV - matchTemplate image template matching
如何让你的量化交易系统具有概率优势,具有正向收益预期呢?
navicat for Oraclel链接oracle 报错oracle library is not loaded的解决办法
光线的数值追踪
走得通,看得见!你的交通“好帮手”









![[MySql] implement multi-table query - one-to-one, one-to-many](/img/7e/8f1af4422a394969b28a553ead2c42.png)