Considering following example:
#include <iostream>
using namespace std;
struct Test
{
uint8_t A:1;
uint8_t B:1;
uint8_t C:1;
uint8_t D:1;
};
int main()
{
Test test;
test.A = 1;
test.B = 0;
test.C = 1;
test.D = 0;
int bitmask = test.A | (test.B << 1) | (test.C << 2) | (test.D << 3);
cout << "Size: " << sizeof(test) << ", bitmask: " << bitmask;
return 0;
}
I'm assuming that the data in the bitfield is represented as bitmask somehow? I was wondering if there is a way to get a bitmask directly, without having to go through and shift all members. In this case it's not a big deal, but if you have large bitfield it can get pretty tedious.
For example it would be great if I could do something like this:
int bitmask = (int)test;
Of course that doesn't work. Any way to achieve similar robustness?