fork download
  1.  
  2.  
  3. #pragma pack(push, 8)
  4. struct A
  5. {
  6. char c, d;
  7. };
  8. #pragma pack(pop)
  9.  
  10.  
  11. struct B
  12. {
  13. _Alignas(8) char c;
  14. _Alignas(8) char d;
  15. };
  16.  
  17. ///////
  18.  
  19. #pragma pack(push, 1)
  20. struct C
  21. {
  22. float c, d;
  23. };
  24. #pragma pack(pop)
  25.  
  26. /* crash, because
  27.  
  28.   error: ‘_Alignas’ specifiers cannot reduce alignment of ‘c’
  29.  
  30. struct D
  31. {
  32. _Alignas(1) float c;
  33. _Alignas(1) float d;
  34. };
  35. */
  36.  
  37.  
  38. #include <stdio.h>
  39.  
  40. int main(int argc, char** argv)
  41. {
  42. struct A a;
  43. struct B b;
  44. struct C c;
  45. // struct D d;
  46. printf("size of A = %llu\n", sizeof(a));
  47. printf("size of B = %llu\n", sizeof(b));
  48. printf("size of C = %llu\n", sizeof(c));
  49. // printf("size of D = %llu\n", sizeof(d));
  50.  
  51. return 0;
  52. }
Success #stdin #stdout 0s 5680KB
stdin
Standard input is empty
stdout
size of A = 2
size of B = 16
size of C = 8