转一篇文章。写的比较好,浅显易懂,还画了图。

https://www.cnblogs.com/idorax/p/6796897.html

概况一下:

container_of用到了typeof和offsetof。

1. typeof是gcc的扩展,不是C标准操作符。

2. offsetof就是这样一个语句:

((size_t)&((TYPE *)0)->MEMBER)

[dev]typeof, offsetof 和container_of的更多相关文章

  1. typeof, offsetof 和container_of

    要理解Linux中实现的双向循环链表("侵入式"链表),首先得弄明白宏container_of. 本文尝试从gcc的关键字typeof和宏offsetof入手,循序渐进地剖析宏co ...

  2. linux中offsetof与container_of宏定义

    linux内核中offsetof与container_of的宏定义 #define offsetof(TYPE, MEMBER)    ((size_t) &((TYPE *)0)->M ...

  3. (转)offsetof与container_of宏[总结]

    1.前言 今天在看代码时,遇到offsetof和container_of两个宏,觉得很有意思,功能很强大.offsetof是用来判断结构体中成员的偏移位置,container_of宏用来根据成员的地址 ...

  4. offsetof与container_of宏[总结]

    1.前言 今天在看代码时,遇到offsetof和container_of两个宏,觉得很有意思,功能很强大.offsetof是用来判断结构体中成员的偏移位置,container_of宏用来根据成员的地址 ...

  5. typeof、offsetof、container_of的解释

    链表是内核最经典的数据结构之一,说到链表就不得不提及内核最经典(没有之一)的宏container_of. container_of似乎就是为链表而生的,它的主要作用是根据一个结构体变量中的一个域成员变 ...

  6. typeof, offsetof, container_of宏

    container_of宏实现如下: #define container_of(ptr, type, member) ({ \ )->member ) *__mptr = (ptr); \ (t ...

  7. C语言笔记(结构体与offsetof、container_of之前的关系)

    关于结构体学习,需要了解:结构体的定义和使用.内存对齐.结构体指针.得到结构体元素的偏移量(offsetof宏实现) 一.复习结构体的基本定义和使用 typedef struct mystruct { ...

  8. offsetof与container_of宏分析

    offsetof宏:结构体成员相对结构体的偏移位置 container_of:根据结构体成员的地址来获取结构体的地址 offsetof 宏 原型: #define offsetof(TYPE, MEM ...

  9. 对offsetof、 container_of宏和结构体的理解

    offsetof 宏 #include<stdio.h> #define offsetoff(type, member)      ((int)&((type*)0)->me ...

随机推荐

  1. Python学习笔记-Linux下安装Python

    Linux系统CentOS 1.安装依赖组件 yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel s ...

  2. PHP 【二】

    EOF EOF(heredoc)是一种在命令行shell(如sh.csh.ksh.bash.PowerShell和zsh)和程序语言(像Perl.PHP.Python和Ruby)里定义一个字符串的方法 ...

  3. Django组件-分页器

    Django的分页器(paginator) view from django.shortcuts import render,HttpResponse # Create your views here ...

  4. fiddler主要图标说明

    主要图标含义说明: 正在将请求数据发往服务器 正在从服务器下载返回数据 请求过程中暂停 返回过程中暂停 请求中使用了HTTP HEAD方法; 返回中应该没有body内容 请求中使用了HTTP CONN ...

  5. 1.arm的linux系统搭建

    从裸板到系统 一般是CPU内部有启动代码,如nuvoton的nuc900系列的芯片内部就有ibr程序,来控制启动过程,在usb启动时负责加载usb驱动,这样在pc端就可以识别到usb设备了,然后通过t ...

  6. liunx redis集群添加密码

    第一种方法: 修改每个节点redis.conf配置文件: masterauth 123456 requirepass 123456 各个节点的密码都必须一致,否则Redirected就会失败 重新启动 ...

  7. js分析 邮箱地址加密 [email protected]

    0.参考 https://segmentfault.com/q/1010000000117476 javascript里function之前加上感叹号 ' ! ' 会怎么样? // 这么写会报错,因为 ...

  8. Python学习(四十)—— Djago之认证系统

    一.COOKIE 与 SESSION 概念 cookie不属于http协议范围,由于http协议无法保持状态,但实际情况,我们却又需要“保持状态”,因此cookie就是在这样一个场景下诞生. cook ...

  9. js检测访问设备

    if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) { }

  10. XVII Open Cup named after E.V. Pankratiev. GP of Two Capitals

    A. Artifact Guarding 选出的守卫需要满足$\max(a+b)\leq \sum a$,从小到大枚举每个值作为$\max(a+b)$,在权值线段树上找到最大的若干个$a$即可. 时间 ...