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 Reply Children
  • The Standard specifies that bitfields are to be of the "unsigned" type, not "unsigned char" type. However, many compilers, C51 included, allow for other types (e.g., unsigned char) to provide widths narrower than sizeof(unsigned).

  • It just occurred to me that my narrowing what the Standard says to suit your unsigned usage could be misleading. The Standard actually says that a bitfield may have type int, unsigned int, or signed int. I was limiting my reply to unsigned because you were using unsigned types, but my comment about "nonstandard bitfield type" would apply to signed char as well.