offset求结构体成员的偏移量
2014-09-25 11:25
183 查看
【代码】
C++ Code
C++ Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | /* version: 1.0 author: hellogiser blog: http://www.cnblogs.com/hellogiser date: 2014/9/25 */ #include "stdafx.h" #include <iostream> using namespace std; #define OFFSET(s,m) ((int)(&(((s*)0)->m))) struct MyStruct { int a; int b; int c; }; void test_offset() { cout << OFFSET(MyStruct, a) << endl; // 0 cout << OFFSET(MyStruct, b) << endl; // 4 cout << OFFSET(MyStruct, c) << endl; // 8 } int main() { test_offset(); return 0; } |
相关文章推荐
- 如何确定域在结构中的字节偏移量,怎样用结构成员名访问对应成员?
- 从Linux内核代码中学习获得结构体成员偏移量的方法 .
- 结构体成员的偏移量与offsetof函数
- [C/C++标准库]_[初级]_[计算结构体成员的偏移量]
- 计算结构体内成员的内存偏移量
- 求取结构体成员偏移量的宏定义
- [C/C++标准库]_[初级]_[计算结构体成员的偏移量]
- 计算结构体成员地址偏移量...
- ANSI C中获取结构体成员偏移量量的办法
- c语言 获取结构体成员偏移量方法
- 定义一个宏,求出给定结构中给定成员的偏移量
- 通过宏定义取结构本中成员的偏移量
- 求结构体成员偏移量的三种方法
- 不实例化结构体获取结构体成员在结构体中的偏移量
- 结构体成员偏移量的计算
- gdb 显示结构体中成员的偏移量
- C语言计算一个结构体内成员地址的偏移量的两种方法(代码实例)
- 从Linux内核代码中学习获得结构体成员偏移量的方法
- 用宏来求结构成员偏移量
- 结构体成员偏移量,标准C其实有定义宏实现