为什么以下表达式不会产生(空指针)运行时错误?
typedef struct{
int a,b,c;
} st;
st obj={10,12,15};
st *ptr1=&obj;
st *ptr2=NULL;
printf("%d",*(int *)((char*)ptr1+(int)&ptr2->b));
<stddef.h>
头文件中的offsetof
宏。(offsetof
通常是基于空指针算术实现的,但这是因为它是与特定编译器一起使用的C库的一部分,所以编写者知道编译器会处理它。) - aschepler