[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] question about bit-fields

From: grischka
Subject: Re: [Tinycc-devel] question about bit-fields
Date: Mon, 22 Oct 2012 21:55:47 +0200
User-agent: Thunderbird (Windows/20100228)

Didier Barvaux wrote:
On a structure such as:
  struct mystruct1
     unsigned int mystruct1_foo:4;
     unsigned int mystruct1_bar:4;
     uint8_t mystruct1_other;
     uint16_t mystruct1_other2;

The 2 first fields uses 1 byte with GCC/Clang while they use
sizeof(unsigned int) bytes with TCC. GCC/Clang pack the bit fields on
the smaller type available. So, sizeof(struct mystruct1) = 4 with
GCC/Clang and sizeof(struct mystruct1) = 8 with TCC.

I tried your "bitfield.c" test with GCC and it failed on the 2nd
assertion.  Hm ...

--- grischka

My program (and probably many others, as the struct iphdr for IPv4
header defined by the GNU libc is defined that way) relies on this
behaviour. That's why I created the patch. It packs bit fields "the way
GCC does". If you got a better description, I'll be happy to change
it :)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]