fork download
  1. #include <iostream>
  2. #include <cstddef>
  3. using namespace std;
  4.  
  5. struct Inner_S
  6. {
  7. double a;
  8. double b[4][4];
  9. };
  10.  
  11. #pragma pack(1)
  12. struct Packed_S
  13. {
  14. uint8_t c;
  15. Inner_S d;
  16. };
  17.  
  18. int main() {
  19. cout << "Size: " << sizeof(Packed_S) << endl;
  20. cout << "c offset: " << offsetof(Packed_S, c) << endl;
  21. cout << "d offset: " << offsetof(Packed_S, d) << endl;
  22. cout << "a offset: " << offsetof(Packed_S, d.a) << endl;
  23. cout << "b offset: " << offsetof(Packed_S, d.b) << endl;
  24. return 0;
  25. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Size: 137
c offset: 0
d offset: 1
a offset: 1
b offset: 9