3 ms·
That should be: Parent* p = container_of(field,Parent,pa_somefield); access(p->pa_otherfield); You'd usually define container_of using subtraction (not ne
by a1369209993 6y ago
That should be:
Parent* p = container_of(field,Parent,pa_somefield);
access(p->pa_otherfield);
You'd usually define container_of using subtraction (not negative offset per se):
#define container_of(FIELD,TYPE,MEMB) ({ \
const typeof( ((TYPE*)0)->MEMB )* _mptr = (FIELD); \
(TYPE*)( (char*)_mptr - __builtin_offsetof(TYPE,MEMB) ); \
})
but you shouldn't actually be using that directly, because thats what the macro is for.