fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. typedef unsigned char u8;
  6. typedef unsigned int u32;
  7.  
  8. class Test {
  9. u8 four_bit_field : 4;
  10. u8 eight_bit_field;
  11. u32 twenty_bit_field : 20;
  12. }__attribute__((packed));
  13.  
  14. class Test2 {
  15. u8 four_bit_field : 4;
  16. u8 eight_bit_field : 8;
  17. u32 twenty_bit_field : 20;
  18. }__attribute__((packed));
  19.  
  20. int main()
  21. {
  22. cout << sizeof(Test) << endl;
  23. cout << sizeof(Test2) << endl;
  24. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
5
4