This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

struct definition problem

Hi,

I'm using KEIL uVision2 V2.20a, This definition doesn't work, anyone know why ?

Usually I'm using this to access each bit separatly in a byte, rather than using shifting ans masking. In my MPLAB C its working fine. But when using this declaration in KEIL I get the error:

ERROR C150 'b0' bit member in struct/union

My struct definition is:

struct structSplitByte
{
bit b0;
bit b1;
bit b2;
bit b3;
bit b4;
bit b5;
bit b6;
bit b7;
};

union unionSplit
{
struct structSplitByte Split;
char cValue;
};



Or does anyone know a better and easy way to access the value of one bit in a byte ?

Thank you,

Aldrin,

Parents Reply Children
  • The bit field method would look something like this:

    struct structSplitByte
    {
        unsigned char    b0:1;
        unsigned char    b1:1;
        unsigned char    b2:1;
        unsigned char    b3:1;
        unsigned char    b4:1;
        unsigned char    b5:1;
        unsigned char    b6:1;
        unsigned char    b7:1;
    };
    
    union unionSplit
    {
        struct structSplitByte Split;
        char cValue;
    };
    
    This does give nice neat source code, but is potentially difficult to port as C does not specify the order of the bit fields in memory. Also, Keil is sometimes rather inefficient when accessing 1-bit fields.

    The most portable method is to use masks.

  • "...is potentially difficult to port as C does not specify the order of the bit fields in memory"

    and has its own difficulties in C51, as Keil's implementation can be somewhat unexpected!

    Search the knowledgebase (and this forum) as there are articles on the common pitfalls!

    Another reason to stick with the masks...?