3 ms·
To get from a pointer to member to a pointer to an object, you have to subtract the offset of the member within the struct from the pointer you have. The point
by Someone 12y ago
To get from a pointer to member to a pointer to an object, you have to subtract the offset of the member within the struct from the pointer you have.
The point of discussion is that there is no portable way to write the 'offsetof' macro, even though every compiler on the planet (AFAIK, YMMV) works fine with
#define offsetof(st, m) ((size_t)(&((st *)0)->m))
See http://en.m.wikipedia.org/wiki/Offsetof#Implementation http://en.m.wikipedia.org/wiki/Offsetof#Implementation, http://stackoverflow.com/questions/6700114/portability-of-using-stddef-hs-offsetof-rather-than-rolling-your-own http://stackoverflow.com/questions/6700114/portability-of-us...
Long story short: use what your compiler provides in stddef.h, and you'll be fine. If it doesn't provide offsetof, migrate to a modern ISO C compiler, or copy the definition used above, and test.