====== 结构体成员的地址分布 ====== C编译器对结构体(struct)对象的成员按地址增序的方式进行空间分配,即第一个成员的地址就是整个结构体对象的起始地址,其他成员按定义顺序依次排在后面。 例如: struct { int a, b, c; } s; int *p = &s.a; int *q = &s.b; 则p struct iphdr { #if __BYTE_ORDER == __LITTLE_ENDIAN unsigned int ihl:4; unsigned int version:4; #elif __BYTE_ORDER == __BIG_ENDIAN unsigned int version:4; unsigned int ihl:4; #else # error "Please fix " #endif u_int8_t tos; u_int16_t tot_len; u_int16_t id; u_int16_t frag_off; u_int8_t ttl; u_int8_t protocol; u_int16_t check; u_int32_t saddr; u_int32_t daddr; /*The options start here. */ }; {{tag>C语言}}