How do you read the second line of this macro? What does (type *)0 mean in this context?
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re finding the type of
((type *)0)->member. It’s not actually dereferencing the pointer (that would be madness, I tell you. Madness!)It’s a weirdness of C. Maybe it would make more sense if they wrote
typeof(type.member)but sadly that is not allowed.