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
"... 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;
union LATCH{ unsigned char Value; struct { unsigned char Address :3; unsigned char Data :1; unsigned char Gate :1; unsigned char Clear :1; }_74HC259; }Latch;
"Or use a nonstandard bitfield type:" what do you mean?
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.
It is an 8052. why not use a bit addresable byte.
Because it doesn't help to improve the readability of code.