0
我想在Visual C使用此結構:位字段問題++的Visual C++
struct iphdr
{
unsigned int ihl:4;
unsigned int version:4;
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;
struct in_addr ip_src;
struct in_addr ip_dst;
};
,但在調試的時候,我發現sizeof(struct iphdr) = 24
,這有望成爲20
而且很奇怪的是,當我更換ihl
和version
用char
,sizeof(struct iphdr) = 20
你在32位或64位編譯器上編譯? – 2012-03-04 09:03:10
似乎它不僅僅是通常的結構對齊/填充的東西。 – Mysticial 2012-03-04 09:03:57
@izomorphius不,它是一個32位編譯器,我使用的是vC++ 2008 – Javran 2012-03-04 09:06:23