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

union Problem

i am using the following union in a program.
when i changes any of _74HC259 member field(Address,Data,Gate,Clear), variable Value doesn't changes crosspondingly.

union LATCH{
unsigned char Value;
struct {
unsigned Address:3;
unsigned Data :1;
unsigned Gate :1;
unsigned Clear :1;
}_74HC259;
}Latch;

what is basically the problem, does C51 comiler doesn't handle such type of data structure?
Regards

Parents
  • "... does C51 comiler doesn't handle such type of data structure?"

    Change Value's type:

    union LATCH{
        unsigned Value;
        struct {
            unsigned Address :3;
            unsigned Data    :1;
            unsigned Gate    :1;
            unsigned Clear   :1;
        }_74HC259;
    }Latch;
    Or use a nonstandard bitfield type:
    union LATCH{
        unsigned char Value;
        struct {
            unsigned char Address :3;
            unsigned char Data    :1;
            unsigned char Gate    :1;
            unsigned char Clear   :1;
        }_74HC259;
    }Latch;

Reply
  • "... does C51 comiler doesn't handle such type of data structure?"

    Change Value's type:

    union LATCH{
        unsigned Value;
        struct {
            unsigned Address :3;
            unsigned Data    :1;
            unsigned Gate    :1;
            unsigned Clear   :1;
        }_74HC259;
    }Latch;
    Or use a nonstandard bitfield type:
    union LATCH{
        unsigned char Value;
        struct {
            unsigned char Address :3;
            unsigned char Data    :1;
            unsigned char Gate    :1;
            unsigned char Clear   :1;
        }_74HC259;
    }Latch;

Children