linux和windows平台都已经定义了offsetof函数,用于取struct类型中某个变量的偏移量
#ifdef _WIN64
#define offsetof(s,m) (
size_t)( (
ptrdiff_t)&reinterpret_cast<const volatile char&>((((s *)0)->m)) )
#else
#define offsetof(s,m) (size_t)&reinterpret_cast<const volatile char&>((((s *)0)->m))
#else
#else
#define offsetof(s,m) (size_t)&(((s *)0)->m)
#endif
#endif /* __cplusplus */
编程中的offsetof
原文:http://www.cnblogs.com/davad/p/5172101.html