求结构体的偏移量方法
来源:互联网 发布:smo算法 python实现 编辑:程序博客网 时间:2024/09/21 09:00
在看网关代码的时候进程看到类似于这样的语句:
typedef struct DeviceInfoDetailTable_t{struct DeviceInfoDetailTable_t *Next;u16Len;u16Index;u8extAddr[8];u8EndPoint;u8deviceName[16];u16 AppDeviceID;u16DeviceType;u8roomNo;u8minRange;u8maxRange;//u32standarIRno;u8Reserved[4];u8InClustersNum;u8 OutClustersNum;u16 IOClusters[20];} DeviceInfoDetailTable_Typedef;
( SearchDataBase_Ext1(DeviceInfoDetailTable, (u8 *)&ZCL_Server_p->DestinationAddress[0], 64, (u16)&(((DeviceInfoDetailTable_Typedef *)0) -> extAddr), (u8 *)&DevInfoDetail_buf) == 0 )
里面的参数就是用来去结构体的偏移地址用的:
(u16)&(((DeviceInfoDetailTable_Typedef *)0) -> extAddr)
解释如下:
把0强制转换成类型DeviceInfoDetailTable_Typedef的指针操作:(DeviceInfoDetailTable_Typedef *)0,得到基址为0的结构体;
则通过&(((DeviceInfoDetailTable_Typedef *)0) -> extAddr),就得到了元素extAddr的地址,由于基址为0,所以偏移量被计算出来。
类似的可以使用宏来使用计算偏移量:
#define STRUCT_OFFSET(id, element) ((unsigned long) &((struct id*)0)->element)
0 0
- 求结构体的偏移量方法
- 求结构体成员偏移量的三种方法
- 求结构体成员的偏移量
- 求结构体元素的偏移量
- 求结构体某个变量的相对偏移量
- 求结构体某个变量的相对偏移量
- 结构体的偏移量
- 结构体的偏移量
- 结构体的偏移量
- 指针用法之一:给定结构体求某变量的偏移量,给出某变量偏移量求结构体首地址
- 计算结构体中偏移量的方法
- 结构体偏移量
- 结构体偏移量
- 关于结构体的偏移量
- 结构体成员偏移量的计算
- 结构体的偏移量计算
- 结构体-元素的偏移量
- zz结构体的sizeof 问题以及如何求每个元素的偏移量
- APK构建原理解析
- 线性代数A矩阵乘以A的转置的含义或者几何意义
- JAVA枚举(enum)详解7种常见的用法
- JAVA的solr操作实现(基本操作)
- java当中的定时器的4种使用方式
- 求结构体的偏移量方法
- L2-010. 排座位 (并查集简单应用)
- GCC C语言处理主要函数之c_objc_common_init
- 非极大值抑制算法
- 语言数据联盟( linguistic data consortium,LDC)
- Python Machine Learning
- 移动端的布局:flex布局
- GCC C语言处理主要函数之c_common_init
- solr6.3安装部署