Bitfields in structures

John O'Connor joconnor36@hotmail.com
Fri Sep 27 07:23:00 GMT 2002


Please consider the two almost identical structures below for a structure 
for PortE of Hitachi SH7045F 32-bit MCU. GNU C compiler objects to 3-bit 
bitfield being called 'NIB' but does not object to it being called 'B3' !!!! 
B3 works fine but get message saying 'Structure has no memeber called NIB', 
when this field is named NIB. I cannot understand why this should be. Maybe 
something very subtle going on here? Any help or advice will be most 
appreciated.

Regards,

John O'Connor

struct st_pe {                                       /* struct PE    */
             union {                                 /* PEDR         */
                   unsigned short WORD;              /*  Word Access */
                   struct {                          /*  Bit  Access */
                          unsigned char B15:1;       /*    Bit 15    */
                          unsigned char B14:1;       /*    Bit 14    */
                          unsigned char B13:1;       /*    Bit 13    */
                          unsigned char B12:1;       /*    Bit 12    */
                          unsigned char B11:1;       /*    Bit 11    */
                          unsigned char B10:1;       /*    Bit 10    */
                          unsigned char B9 :1;       /*    Bit  9    */
                          unsigned char B8 :1;       /*    Bit  8    */
                          unsigned char B7 :1;       /*    Bit  7    */
                          unsigned char B6 :1;       /*    Bit  6    */
                          unsigned char B5 :1;       /*    Bit  5    */
                          unsigned char B4 :1;       /*    Bit  4    */
                          unsigned char B3 :3;       /*   Bits 3,2,1 */
                          unsigned char B0 :1;       /*    Bit  0    */
                          }       BIT;               /*              */
                   }            DR;                  /*              */
};

struct st_pe {                                       /* struct PE    */
             union {                                 /* PEDR         */
                   unsigned short WORD;              /*  Word Access */
                   struct {                          /*  Bit  Access */
                          unsigned char B15:1;       /*    Bit 15    */
                          unsigned char B14:1;       /*    Bit 14    */
                          unsigned char B13:1;       /*    Bit 13    */
                          unsigned char B12:1;       /*    Bit 12    */
                          unsigned char B11:1;       /*    Bit 11    */
                          unsigned char B10:1;       /*    Bit 10    */
                          unsigned char B9 :1;       /*    Bit  9    */
                          unsigned char B8 :1;       /*    Bit  8    */
                          unsigned char B7 :1;       /*    Bit  7    */
                          unsigned char B6 :1;       /*    Bit  6    */
                          unsigned char B5 :1;       /*    Bit  5    */
                          unsigned char B4 :1;       /*    Bit  4    */
                          unsigned char NIB:3;       /*   Bits 3,2,1 */
                          unsigned char B0 :1;       /*    Bit  0    */
                          }       BIT;               /*              */
                   }            DR;                  /*              */
};




_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com



More information about the Gcc-help mailing list