#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
typedef struct student{
int x;
double y;
char z;
}mystudent;
//返回结构体的起始地址
#define container_of(ptr, type, member) ({ /
const typeof( ((type *)0)->member ) *__mptr = (ptr); /
(type *)( (char *)__mptr - offsetof(type,member) );})
int main(void)
{
mystudent *p = NULL;
mystudent x;
x.x = 10;
p = container_of(&x.z,mystudent,z);
printf("%d/n", p->x);
return 0;
}
typeof的用法
Another way to refer to the type of an expression is with typeof. The syntax of using of
this keyword looks like sizeof, but the construct acts semantically lik