PATCH: type safe(r) list_entry repacement: generic_out_cast
Quoted 3 lines · Kevin O'Connor
#define BackPtr(ptr, type, member) ({ \
typeof( ((type *)0)->member ) *__mptr = (ptr); \
((type *)( (char *)__mptr - (unsigned long)(&((type *)0)->member) ));})I've seen this sort of code several times now in the Linux kernel, and I've never liked it. Is there some reason why you guys avoid offsetof() like the plague?
/Mikael
In article <[email protected]>,
Quoted 8 lines · Mikael Pettersson
Quoted 3 lines · Kevin O'Connor
#define BackPtr(ptr, type, member) ({ \ typeof( ((type *)0)->member ) *__mptr = (ptr); \ ((type *)( (char *)__mptr - (unsigned long)(&((type *)0)->member) ));})I've seen this sort of code several times now in the Linux kernel, and I've never liked it. Is there some reason why you guys avoid
offsetof()like the plague?
Trivial answer: offsetof() does not exist when you don't have system header files.
So it's not that it's getting avoided, it _has_ to be re-implemented anyway. And once you do that, you might as well do it right (ie what the kernel wants is not offsetof, but a new pointer.
Linus