You can try the following:
struct FooWord2 { union { struct { unsigned int Fill : 8; unsigned int A_Bit : 1; unsigned int someData3 : 23; }; struct { unsigned int : 8; unsigned int B_Bit : 1; }; }; };
It is worth mentioning: according to this answer, anonymous structures are not a C ++ standard, but an extension. GCC, MSVC permissions - as far as I remember. too. LLVM? Not sure, but, as often close to GCC, that will also be so.
In standard matching libraries, they use macros to get the correct effect, for example:
struct FooWord2 { unsigned int Fill : 8; unsigned int A_Bit : 1; unsigned int someData3 : 23; }; #define B_Bit A_Bit
Just explanatory: with your source code, you got this effect:
- Fills a new bit field
- union is a different data type, so the previous bit field is completed
- Inside the union, a new bit field begins. I am not sure if this creates a single bit or perhaps a bit field with two entries. Perhaps someone can shed light on what the standard state is ...
- Closing the union, bit-bit is also complete.
- someData3 then launches a new bit field
Thus, the bias you want to avoid.
source share