- #include<stdio.h>
- #include<string.h>
- #define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER)
- #define container_of(ptr, type, member) ({ \\
- const typeof( ((type *)0)->member ) *__mptr = (ptr); \\
- (type *)( (char *)__mptr - offsetof(type,member) );})
- #define pppp ({ pp = 5; pp -3 ;})
- struct data{
- int a;
- char b;
- char c[10];
- };
- #define test struct data
- int main()
- {
- struct data loc;
- int pp = 4;
- loc.a = 3;
- char dd[10] = "baibin";
- strcpy(loc.c,dd);
- struct data *pdata ;
- pdata = container_of(&(loc.b),struct data,b);
- printf("a=%d, c=%s",pdata->a,pdata->c);
- pp = ( {pp= 5; pp-2;});
- printf("\\n%d\\n",pp);
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/080720134475.html
来源: http://www.codesnippet.cn/detail/080720134475.html