[email protected] wrote:
Hi,

I've got a problem with msp430-gcc structure sizes / packing:

When compiling the following code with a newer version of mspgcc (e. g. 
mspgcc-20081230.exe or a topic cvs-build) the variable xaver is six byte in 
memory:

typedef struct {
   struct {
unsigned a : 1; unsigned b : 1;
     unsigned c : 1;
     unsigned d : 1;
     unsigned e : 4;
   } BIT;
  unsigned char x;
  unsigned int  y;
} mytype;

mytype xaver;

int main() {
}

When compiling it with an older version (e. g. mspgcc-20080619.exe), xaver has 
only a size of four bytes.

Can anybody explain me why?
Because of unsigned int base type of bitfield. It takes 2 bytes. Next field takes one byte and one byte padded to align y to 2-bytes address boundary.
Can I avoid packing the new way?
use correct type for bitfield:

  struct {
     unsigned char a  : 1;
     ......
    } BIT;


--
Regards,
  Sergey A. Borshch            mailto: [email protected]
    SB ELDI ltd. Riga, Latvia

Reply via email to