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.
unsigned char a : 1,
b : 1,
c : 1,
unsigned char num;
static const STNAME c1 =
static const STNAME c2 =
(0x01 | 0x02| 0x03)
int _tmain(int argc, _TCHAR* argv)
name1.a = 0x1;
name1.b = 0x1;
name1.c = 0x1;
name3 = c1; // does not assign 0x7 (or 1 to each of a,b,c)
name4 = c2; // does not assign 0x7(or 1 to each of a,b,c)