#define offsetof(TYPE, MEMBER) ((unsigned int) &((TYPE *)0)->MEMBER)
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
struct student {
char name[20];
char sex;
};
void main(void)
{
// off_set = offsetof(student_info, age);
// stu_info.age = 10;
// ptr = container_of(&stu_info.age, student_info, age);
struct student st={"zhangsan",'m'};
struct student *tmp;
char *ptr_name=st.name;
tmp=container_of(ptr_name,struct student,name);
}
|