fork(3) download
  1. #include <iostream>
  2. #include <cstddef>
  3. using namespace std;
  4.  
  5. #pragma pack(1)
  6. struct STestPragmaPack {
  7. char c;
  8. long d;
  9. } datasPP;
  10. #pragma pack()
  11.  
  12. struct STestAttributPacked {
  13. char c;
  14. long d;
  15. } __attribute__((packed)) datasAP;
  16.  
  17. struct STestAlignas {
  18. char c;
  19. alignas(char) long d;
  20. } datasA;
  21.  
  22. int main() {
  23. cout << "pragma pack = " << sizeof(datasPP) << endl;
  24. cout << "attribute packed = " << sizeof(datasAP) << endl;
  25. cout << "alignas = " << sizeof(STestAlignas) << endl;
  26. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
pragma pack = 5
attribute packed = 5
alignas = 8