I've just done a test with bitfields, and the results are surprising me.
class test1 {
public:
bool test_a:1;
bool test_b:1;
bool test_c:1;
bool test_d:1;
bool test_e:1;
bool test_f:1;
bool test_g:1;
bool test_h:1;
};
class test2 {
public:
int test_a:1;
int test_b:1;
int test_c:1;
int test_d:1;
int test_e:1;
int test_f:1;
int test_g:1;
int test_h:1;
};
class test3 {
public:
int test_a:1;
bool test_b:1;
int test_c:1;
bool test_d:1;
int test_e:1;
bool test_f:1;
int test_g:1;
bool test_h:1;
};
The results were:-
sizeof(test1) = 1 // This is what I'd expect. 8 bits in a byte
sizeof(test2) = 4 // Reasonable. Maybe padded out to the size of an int.
sizeof(test3) = 16 // What???
Is this what you'd expect, or a compiler bug? (Codegear C++ Builder 2007, btw...)