zhangyimb zhangyimb

About BitField

Discussion created by zhangyimb zhangyimb on Jun 1, 2012
Latest reply on Jun 1, 2012 by zhangyimb zhangyimb

Hello! I'm using XET256  CodeWarrior IDE version V5.9.0

 

I have defined a UNION  

typedef union{     struct{        word XLength:8;        word nouse:5;        word datatype:1;        word operation:2;            }Sx;  struct{  word XLength:5;  word YLength:8;  word datatype:1;  word operation:2; }Sxy;    struct{  word lbits: 10;  word invalidFlag: 1;  word hbits: 5; }Sinvalid;  word w;}UIndexType;UIndexType typeP;typeP.w=0x401e;

 but in debug ,the result is  so wrong ,

typeP    Sx                          <2> struct        XLength                 0x40 unsigned char [0:8]        nouse                   0x1e unsigned char [0:5]        datatype                0x0  unsigned char [5:1]        operation               0x0  unsigned char [6:2]    Sxy                         <2> struct        XLength                 0x1e unsigned short[0:5]        YLength                 0x0  unsigned shor[5:8]        datatype                0x0  unsigned short[13:1]        operation               0x1  unsigned short[14:2]    Sinvalid                    <2> struct        lbits                   0x1e unsigned short[0:10]        invalidFlag             0x0  unsigned shor[10:1]        hbits                   0x8  unsigned short[11:5]    w                      0x401e unsigned int  

And if I define  word  XLength :9   word nouse:5  the result is right , 

what's wrong of that ? The same code in CodeWarrior IDE version v4.6 is al right.I am being crazy. if there are some bugs in IDE Please tell me  I'm in hurry.

Outcomes