#include <stdio.h>
struct foo {
size_t a;
size_t b;
char c;
};
#define offsetof(type, member) \
((size_t)(&((type*)0)->member))
#define container_of(ptr, type, member) \
((type*)((char*)ptr - offsetof(type, member)))
int main()
{
int a = 3000;
a = ({ int a = 200; a; });
struct foo s = {
.a = 100,
.b = 200,
.c = 10,
};
printf("%ld\n", container_of(&s.b, struct foo, b)->a);
return 0;
}
container_of
最新推荐文章于 2024-06-22 11:37:32 发布