当前位置:网站首页>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) );})
边栏推荐
- 用户如何正确去认识程序化交易?
- redis从入门到精通
- Mathematica 数据分析(简明)
- bin文档读写
- Two-dimensional array to realize the eight queens problem
- My MySQL database was attacked and deleted for ransom, forcing me to use all my might to recover data
- docker安装nacos并且指定容器数据卷,数据库连接等
- DMPE-PEG-Mal Maleimide-PEG-DMPE dimyristoylphosphatidylethanolamine-polyethylene glycol-maleimide
- Qt对话框中show和exec的区别
- C写菜单指令的快捷方法
猜你喜欢

How to create a new project with VS+Qt

Shell functions and arrays

Suddenly want to analyze the mortgage interest rate and interest calculation

redis从入门到精通

ASP.Net Core实战——身份认证(JWT鉴权)

Startup error: Caused by: org.apache.ibatis.binding.BindingException summary solution

原子的核型结构及氢原子的波尔理论

方法学习笔记

在服务器上远程使用tensorboard

Qt控件-QTextEdit使用记录
随机推荐
docke安装mysql以及主从搭建(并且指定数据生成路径)
为什么要学编译原理
EasyExcel的应用
在服务器上远程使用tensorboard
OpenCV - matchTemplate image template matching
【C语言初阶】求最小公倍数的三种方法
ImageWatch无法显示图像
Servlet life cycle
职业量化交易员对量化交易有什么看法?
redis从入门到精通
Qt对话框中show和exec的区别
二叉排序树的左旋与右旋
内存泄露检测工具VLD(Visual Leak Detector)使用说明
经典面试题 之 TCP 三次握手/ 四次挥手
Startup error: Caused by: org.apache.ibatis.binding.BindingException summary solution
How to flexibly use the advantages of the quantitative trading interface to complement each other?
注解与反射
百度地图——鹰眼轨迹服务
OpenCV简介与搭建使用环境
VS2010: devenv.sln solution save dialog appears