对offsetof的理解:
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
参照
typedef struct {
int min;
char ch;
char ch1;
int min1;
}str;
printf("%x", (unsigned long) ( &( (struct str *)0->min ) ) );
printf("%x", (unsigned long) ( &( (struct str *)0->ch) ) );
printf("%x", (unsigned long) ( &( (struct str *)0->min1 ) ) );
printf("%x", (unsigned long) ( &( (struct str *)0->ch1) ) );
result:
0
4
5
8
阅读(831) | 评论(0) | 转发(0) |