数据结构定义如下:
typedef struct a_s{
long long id_;
}a_t;
typedef struct b_s{
int seq_;
int c_;
}b_t;
typedef struct test_s{
a_t a_;
b_t *b_;
}test_t;
calloc一个test_t t1 对象。如果已知该对象的a_的地址,怎么能获取到t1的b指针对应的c的值呢?
自己原来写的代码如下,取的时候有问题:
int offset = offsetof(struct test_s,b_);
int a_add = (int)&(t->a_);
int b_add = a_add + offset;
b_t *b1 = (b_t *)*b_add;
int c = b1->c_;
printf("%d\n",c);
谢谢各位。