This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Weird bit-field problem in egcs-1.1.1 and egcs-1.1.2pre2...?
- To: Rick Flower <Rick dot Flower at trw dot com>
- Subject: Re: Weird bit-field problem in egcs-1.1.1 and egcs-1.1.2pre2...?
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 19 Mar 1999 02:35:03 -0300
- Cc: egcs-bugs mailing-list <egcs-bugs at egcs dot cygnus dot com>
- References: <14065.28863.848839.344499@gargle.gargle.HOWL>
On Mar 18, 1999, Rick Flower <Rick.Flower@trw.com> wrote:
> If you change the "int"s in the struct below from "int" to "UWORD" you
> will get a different sized structure.
> typedef unsigned short UWORD; // Define a unsigned word
> typedef struct { int field_1 : 14; int field_2 : 3; int field_3 : 9;
> int field_4 : 6; } Header_rType;
Which appears to be correct, since 14+3 bits won't fit in a 16 bit
integer, so field_2 is left for the second UWORD. field_3 will fit in
it too, but field_4 won't, so a third UWORD is allocated. I'm not
sure a compiler is allowed to optimize such bit-field alocation so as
to use a single 32-bit word, but gcc's behavior is certainly correct
for not doing it.
--
Alexandre Oliva http://www.dcc.unicamp.br/~oliva aoliva@{acm.org,computer.org}
oliva@{dcc.unicamp.br,gnu.org,egcs.cygnus.com,samba.org}
Instituto de Computação, Universidade Estadual de Campinas, SP, Brasil
*** E-mail about software projects will be forwarded to mailing lists