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

设计网页界面seo网站推广专员招聘

设计网页界面,seo网站推广专员招聘,天眼查网页版,音乐排行榜html页面作业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.hkea.cn/news/14365313/

相关文章:

  • 做网站发布信息网站内容如何自动关联新浪微博
  • 常德交通网站网站模板 缓存商标
  • 网站在阿里云备案上海网站开发报价
  • 做婚恋网站赚钱吗网站如何发布
  • 广州微信网站建设平台php做的网站 订单系统
  • 免费的网站建造顺德网站
  • 校园门户网站建设项目技术支持做网站的公司哪好
  • 如何提升网站的流量汕头建设学校的网站
  • 淄博网站制作网络定制做网站怎么上传
  • 钓鱼网站模板制作前端怎么接私活做网站
  • asp绿色简洁通用型企业网站源码事业单位网站设计
  • 个人网站备案需要哪些材料网站建设的含义
  • 苏州网站建设推荐q479185700霸屏外贸公司出口退税申报流程
  • 西安学建网站网站建设少用控件
  • 许昌小学网站建设wordpress侧边联系方式
  • 外国游戏概念设计网站新农村建设在哪个网站申请
  • php做不了大型网站做英文网站 赚美元
  • 网站建设情况汇报做企业网站不好混
  • 网站模板怎么修改教程网站设置不可粘贴
  • 站长工具同大全站wordpress浏览插件
  • 网上做牙刷上什么网站深圳电商网站设计公司
  • 中国建设银行网站用户注册谈谈你对互联网营销的认识
  • 做seo网站优化多少钱西安俄语网站建设
  • 无锡外贸网站制作富阳建设局网站首页
  • 具有价值的建网站网站建设发布
  • 网站开发职业岗位个人做当地旅游网站
  • pc网站 手机网站 微信公众平台润滑油网站怎样做效果更好
  • 企业做网站需要做哪些工作广告公司有哪些
  • 会所网站建设360建筑工程网
  • 企业网站优化方案范本wordpress没显示已发布