fork download
  1. #include <stdio.h>
  2.  
  3. struct __attribute__((__packed__)) {
  4. unsigned char ch8;
  5. unsigned short sh16;
  6. unsigned int l32;
  7. }mystruct1 = { 0xAA, 0xBBBB, 0xCCCCCCCC };
  8.  
  9. struct __attribute__((__packed__)){
  10. unsigned char ch8_1;
  11. unsigned short sh16;
  12. unsigned char ch8_2;
  13. unsigned int l32;
  14. }mystruct2 = { 0x11, 0x2222, 0x11, 0x33333333 };
  15.  
  16. struct{
  17. unsigned char ch8_1;
  18. unsigned char ch8_2;
  19. unsigned short sh16;
  20. unsigned int l32;
  21. }mystruct3 = { 0x11, 0x11, 0x2222, 0x33333333 };
  22.  
  23. struct{
  24. unsigned short sh16;
  25. unsigned char ch8;
  26. unsigned int l32;
  27. }mystruct4 = { 0xBBBB, 0xAA, 0xCCCCCCCC };
  28.  
  29. void main(void) {
  30. unsigned int struct_size1;
  31. unsigned int struct_size2;
  32. unsigned int struct_size3;
  33. unsigned int struct_size4;
  34. // size here is 8 byte.
  35. struct_size1 = sizeof(mystruct1);
  36. struct_size2 = sizeof(mystruct2);
  37. struct_size3 = sizeof(mystruct3);
  38. struct_size4 = sizeof(mystruct4);
  39. printf("%d %d %d %d", struct_size1, struct_size2 , struct_size3, struct_size4 );
  40. }
  41.  
Runtime error #stdin #stdout 0s 4380KB
stdin
Standard input is empty
stdout
7 8 8 8