当前位置: 首页 > news >正文

湖南网站优化网站设计需要哪些技能

湖南网站优化,网站设计需要哪些技能,都匀网站建设,湖南百度seo排名点击软件container_of 宏 今天遇到了一段这样的代码#xff0c;大致意思是 通过该struct结构体变量的成员的地址来反推该struct结构体变量的地址 并且用到了内核的宏#xff0c;container_of() static inline struct nova_inode_info *NOVA_I(struct inode *inode) {return container…container_of 宏 今天遇到了一段这样的代码大致意思是 通过该struct结构体变量的成员的地址来反推该struct结构体变量的地址 并且用到了内核的宏container_of() static inline struct nova_inode_info *NOVA_I(struct inode *inode) {return container_of(inode, struct nova_inode_info, vfs_inode); }查了查该宏位于include/linux/kernel.h文件 功能由结构体变量的某个成员变量的内存地址来得到该结构体变量的内存地址 参数 该结构体成员变量的地址指针 2. 该结构体的定义类型type) 3. 该结构体成员的变量名具体实现 #define container_of(ptr, type, member) ({ \const typeof( ((type *)0)-member ) *__mptr (ptr); \(type *)( (char *)__mptr - offsetof(type,member) );})原理 用到GCC的typeof预处理语句typeof(x)返回参数x的类型用到了offsetof(type,member)由一个结构成员member得到相对于结构开头的字节偏移量 .在stddef.h中 container_of()做了两步. 模拟该结构体变量指针指向成员然后通过typeof()反推成员的数据类型const typeof( ((type *)0)-member)然后定义一个该成员变量类型的指针就是ptr的数据类型const typeof( ((type *)0)-member) *__mptr (ptr)将__mptr转换为char *按照1个字节计算__mptr减去成员偏移量就是结构体变量的基地址了。再将该地址指针转换为type指针最后表达式返回的是 (type *) (结构体变量基地址) 指针 1. const typeof( ((type *)0)-member) *__mptr (ptr) 2. (char *)__mptr - offsetof(type,member)测试 #include stdio.h #include stddef.h#define everything_to_string(x) #x /* #define container_of(ptr,type,member) ({ \const typeof( ((type *)0)-member ) *__mptr (ptr); \(type *)( (char *)__mptr - offsetof(type,member) );}) */ //const struct member *__mptrptr; //(struct Student *)( (char *)__mptr - offsetof(type,member) ) #define container_of(ptr,type,member) ({ \const typeof( ((type *)0)-member ) *__mptr (ptr); \(type *)((char *)__mptr - offsetof(type,member)); })struct info {int a;int b; }; struct Student {char name[4]; // 0int age; // 4int grade; // 8int sex; // 12struct info last; };int main() {struct Student student{123,22,100,1,{10,20}};struct info *ptrstudent.last;struct Student *pstudent container_of(ptr,struct Student,last);printf([%p]\n,pstudent);printf([%p]\n,ptr);return 0; }参考资料 https://stackoverflow.com/questions/15832301/understanding-container-of-macro-in-the-linux-kernelhttps://gaomf.cn/2017/10/07/C_typeof/https://www.runoob.com/cprogramming/c-macro-offsetof.html
http://www.w-s-a.com/news/141531/

相关文章:

  • 中展建设股份有限公司网站做网站备案是什么意思
  • 石家庄网站建设接单wordpress功能小工具
  • 有没有专门做网站的网站镜像上传到域名空间
  • 网站建设中 windows买域名自己做网站
  • 设计英语宁波seo做排名
  • 奉贤网站建设上海站霸深圳几个区
  • c#做网站自已建网站
  • 成都地区网站建设网站设计类型
  • 如何做网站结构优化北京响应式网站
  • 出售源码的网站威海住房建设局网站
  • 网站建设补充报价单网站建设 技术指标
  • 做网站费用分摊入什么科目做网络网站需要三证么
  • 房屋备案查询系统官网杭州排名优化软件
  • 网站地图html网络营销的流程和方法
  • 注册好网站以后怎么做wordpress 获取插件目录下
  • 南京做网站dmooo地方网站需要什么手续
  • 网站开发合同有效期omeka wordpress对比
  • 杭州设计网站的公司广州网站改版领军企业
  • 网站备案系统苏州网站设计网站开发公司
  • 怎么样做微网站著名企业vi设计
  • 三分钟做网站网页设计心得体会100字
  • 网站建设支付宝seo建站是什么
  • 常州做网站的 武进学雷锋_做美德少年网站
  • 怎样建网站赚钱贵州seo和网络推广
  • 创建网站的工具站内seo优化
  • 网站特效 站长查询网网站
  • 百度移动端网站网站建设设计思想
  • 青岛建设官方网站南宁制作企业网站
  • 校园网站建设管理工作制度大网站开发费用
  • 做logo赚钱的网站分类网站 模板