Consider: #include <stdint.h> struct X { uint32_t a:17; uint8_t b:8; bool c:1; }; #include <iostream> int main() { std::cout << sizeof(X) << '\n'; }
This prints "8", while I'd really expect it to print "4". Even more surprisingly, if b's type is changed from uint8_t to uint16_t, the output /does/ become "4". -- Summary: sizeof simple struct consisting of bit-fields too large and unpredictable Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: gcc-bugzilla at contacts dot eelis dot net GCC host triplet: x86_64-pc-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37119