This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Weird bit-field problem in egcs-1.1.1 and egcs-1.1.2pre2...?


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]