C的offsetof和container_of
#include <stdio.h>
#include <stddef.h>
// #define offsetof(s, m) ? (size_t)&(((s *)0)->m)
?
struct A
{
? ? ? ? int a;
? ? ? ? int b;
};
?
int main()
{
? ? ? ? printf("%d\n", offsetof(struct A, b));
? ? ? ? return 0;
}
http://blog.csdn.net/pengzhixi/article/details/4275887
?
#define container_of(ptr, type, member) \
? ((type *) ((char *) (ptr) - offsetof(type, member)))
?