【发布时间】:2012-06-09 05:19:54
【问题描述】:
这是保证,结构的第一个元素的偏移量是 0? 为了更准确,让我们考虑
struct foo {
int a;
double b;
};
struct foo *ptr=malloc(sizeof(struct foo));
int *int_ptr = &ptr->a;
free(int_ptr)
是否保证在任何操作系统或任何其他因素下始终有效?
【问题讨论】:
-
在 any 操作系统或 any 其他因素下?我不知道是否可以回答 - 是否在语言规范中是另一回事。
-
你的代码不应该是
int *int_ptr = &ptr->a;吗?