#include #include #include #define container_of(ptr, type, member) ({ \ const typeof(((type*)0)->member)* __mptr = (ptr); \ (type*)((char*)__mptr - offsetof(type, member)); }) struct A; struct B; struct A { char m0; int m1; struct B* m2; }; struct B { int m0; char m1; short m2; struct A* m3; float m4; struct A m5; struct B* m6; } __attribute__((slr)); int main(int argc, char** argv) { struct A a = { 'x', 52, NULL }; struct B b = { 1, 2, 3, NULL, 4.f, a, NULL }; b.m2 = 42; struct B* someB = (struct B*)malloc(sizeof(struct B)); float* someB_m4 = &someB->m4; // This is not recognized yet, simply ends up as "add 0x10" container_of(someB_m4, struct B, m4)->m1 = 'x'; return 0; }