求结构体内存偏移地址
来源:互联网 发布:周婷katiechow的淘宝 编辑:程序博客网 时间:2024/04/20 02:12
#include<iostream>
#define OffSet(type,field) ((size_t)&(((type *)0)->field))
using namespace std;
class Mystr
{
public:
char a;
int b;
float c;
double d;
char e;
};
int main()
{
Mystr * str;
str=NULL;
printf("%d\n",str->a);
printf("%d\n",OffSet(Mystr,a));
printf("%d\n",OffSet(Mystr,b));
printf("%d\n",OffSet(Mystr,c));
printf("%d\n",OffSet(Mystr,d));
printf("%d\n",OffSet(Mystr,e));
system("pause");
return 0;
}
#define OffSet(type,field) ((size_t)&(((type *)0)->field))
using namespace std;
class Mystr
{
public:
char a;
int b;
float c;
double d;
char e;
};
int main()
{
Mystr * str;
str=NULL;
printf("%d\n",str->a);
printf("%d\n",OffSet(Mystr,a));
printf("%d\n",OffSet(Mystr,b));
printf("%d\n",OffSet(Mystr,c));
printf("%d\n",OffSet(Mystr,d));
printf("%d\n",OffSet(Mystr,e));
system("pause");
return 0;
}
- 求结构体内存偏移地址
- 结构体内存偏移
- 宏定义求结构体内变量偏移
- sizeof求结构体内存大小
- 结构体成员地址在结构体内的偏移
- 求结构体内成员的偏移和size的宏
- 结构体内存对齐
- 结构体内存对齐
- 结构体内存对齐
- 结构体内存布局
- 结构体内存对齐
- 结构体内存对齐
- 结构体内存对齐
- 结构体内存对齐
- 结构体内存对齐
- 结构体内存对齐
- 结构体内存对齐
- 结构体内存对齐
- C++11 理解 (二十四) 之 可扩展的随机数功能
- Dynamics CRM 2013 初体验(12):Data Encryption
- checked属性只要存在,就会选中,无论其值是什么
- linux kernel driver我的书籍档案
- xshell下ssh乱码问题解决
- 求结构体内存偏移地址
- Dynamics CRM 2013 初体验(13):重构后的客户端
- android 代码设置、打开wifi热点及热点的连接
- js的XMLHttpRequest对象的创建
- 函数的返回值
- Dynamics CRM 2013 初体验(14):重构后的服务端
- JAVA解码递归
- ext4.1编辑性别,radiogroup太难用了,换成combo
- 使用 wget 完成批量下载