Hi all,
I am experiencing a problem with bit fields. I have simplified my original code to a code snippet below:
In the code below, what is wrong with the static const initialization?
I am expecting name3 and name4 to have a value of 7 in variable num OR a value of 1 for a,b,c.
However I see only value of 1 for "a" only in those 2 cases.
The first two name1 and name2 work fine.
Thanks .Code:typedef union { struct { unsigned char a : 1, b : 1, c : 1, : 5; }; unsigned char num; }STNAME; static const STNAME c1 = { (0x07) }; static const STNAME c2 = { (0x01 | 0x02| 0x03) }; int _tmain(int argc, _TCHAR* argv[]) { STNAME name1; name1.a = 0x1; name1.b = 0x1; name1.c = 0x1; STNAME name2; name2.num=0x7; STNAME name3; name3 = c1; // does not assign 0x7 (or 1 to each of a,b,c) STNAME name4; name4 = c2; // does not assign 0x7(or 1 to each of a,b,c) return 0; }



LinkBack URL
About LinkBacks


