Paolo Bonzini wrote: > >> #define offsetof(__a,__b) ((size_t)(&(((__a*)0)->__b))) > In C, the macro will work in practice with all compilers.
In C++, however, some versions of g++ give a warning or error if this macro is used for a type that is not a POD type (that is, a type that has constructors or member functions or similar). I ended up using this definition: #if defined __GNUG__ #define offsetof(type,ident) ((size_t)&(((type*)1)->ident)-1) #else #define offsetof(type,ident) ((size_t)&(((type*)0)->ident)) #endif Bruno