我正在处理如下结构:
struct s1 {
struct s1 *next;
char a[64];
char b[64];
struct s2 *other;
};
struct s2 {
uint32_t x;
uint32_t y;
}
Run Code Online (Sandbox Code Playgroud)
获得指针b后s1,我正在尝试使用指针算法来访问成员s1->other.我尝试过以下方法:
// Assuming we have the following
struct s1 *p1 = ...
char *b = p1->b;
// Offset to get to s2
struct s2 *p2 = (struct s2*) b + 64;
// Access members
uint32_t result = p2->x;
Run Code Online (Sandbox Code Playgroud)
我不认为填充是问题,因为我开始b.