(type *) ((unsigned char *) q -
#include <stddef.h>
#include <stdio.h>
#include <iostream>
using namespace std;
#define q_data(q, type, link) \
(type *) ((unsigned char *) q - offsetof(type, link))
typedef struct b{
int c;
}b_t;
typedef struct a{
b_t b;
}a_t;
int main() {
a_t aa;
b_t* bb= &(aa.b);
bb->c=1;
printf("%p\n",&aa);
printf("%p\n",&bb);
a_t* aa_test=nullptr;
b_t* bb_test;
bb_test=bb;
aa_test = (a_t *)((unsigned char *)bb_test - offsetof(a_t, b));
printf("%p\n",aa_test);
printf("%d",aa_test->b.c);
return 0;
}
本文标题:(type *) ((unsigned char *) q -
本文链接:https://www.haomeiwen.com/subject/gdtmoctx.html
网友评论