In one of the classes that I am working I found some thing like this in the header file:
_flags = 3;
_fVar1 = 0
_flags = 3
Anonymous member structs (classes) are not allowed in C++, so the program is ill-formed as far as the standard is concerned.
Accessing non-active member of a union has undefined behaviour.
So in short: Whatever it does is up to the compiler.
Both of those are allowed in C (the former wasn't allowed until C11, the latter until C99), and by some compilers, as an extension in C++ (and as an extension in earlier versions of C). Let us assume that you use such compiler.
For instance, does setting
_flags = 3means that
_fVar2will be 1 and
_fVar4will be 0?
That is probably the intention. However, the behaviour depends on the representation that the compiler has chosen for the bit fields.
Without making assumptions about the representation, the only sensible thing that you can use the union for is to set all flags to 0 (
_flags = 0), or all flags to 1 (
_flags = -1).
Would removing or adding to the struct means I have to make corresponding changes to codes that touches any of the other members in the union?
Yes, unless the code touches all of the members equally, like the two examples above.