------- Comment #8 from mcvick_e at iname dot com  2006-08-22 16:42 -------

To try to be more helpful here,  after doing a large amount of investigation
into the signature of this problem, it's been observed that the GNU compiler
simply defines (or appears to define) a bitfield (regardless of it's type
(char, short, int)) as nothing more than a byte aligned entity.  Now if the
structure has a larger constituent primitive type (short, int) then the
structure will align to the largest primitive type.

For example.  One of the tests that I performed was simply to define two
structures.

struct foo1 {
   unsigned int    bar1 : 10;
   unsigned int    bar2 : 10;
   unsigned int    bar3 : 12;
   unsigned short  bar4;
   unsigned char   bar5;
};

struct foo2 {
   unsigned int    bar1 : 10;
   unsigned int    bar2 : 10;
   unsigned int    bar3 : 12;
   unsigned short  bar4;
   unsigned char   bar5;
   unsigned char   bar6;
};

foo1 will report the size as being 0x8 (which is correct), where as foo2 will
report the size as 0xA which is incorrect.  It's correct if the structure has
short alignment, however according to the ABI the structure should align to a
32-bit alignment because of the unsigned int bitfield.

Taking the same example above, if you substitute an unsigned int for the
unsigned short, then you get the alignment that you expect across all
situations.  Merely because an integer primitive type is embedded within the
structure.

I hope this helps some.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28763

Reply via email to