fork download
  1. #include <stdio.h>
  2. #include "stdint.h"
  3.  
  4. typedef union {
  5. uint32_t align;
  6. char buf[9];
  7. } my_union_t;
  8.  
  9. int main(void) {
  10. uint8_t a = 'a';
  11. uint8_t b[1] = {0};
  12. uint8_t c[2] = {0};
  13. uint8_t d[3] = {0};
  14. uint8_t e[4] = {0};
  15. uint8_t f[5] = {0};
  16. uint8_t g[6] = {0};
  17. uint8_t h[7] = {0};
  18. uint8_t i[8] = {0};
  19. uint8_t j[9] = {0};
  20. uint8_t k[10] = {0};
  21.  
  22. my_union_t un = {0};
  23. my_union_t un2 = {0};
  24. uint16_t u16 = 10;
  25.  
  26. printf("&a = %p, &b = %p, &c = %p\n", &a, b, c);
  27. printf("&d = %p, &e = %p, &f = %p\n", d, e, f);
  28. printf("&g = %p, &h = %p, &i = %p\n", g, h, i);
  29. printf("&j = %p, &k = %p\n", j, k);
  30. printf("sizeof(my_union_t) = %u\n", sizeof(my_union_t));
  31. printf("&un = %p, &un2 = %p, u16 = %p\n", &un, &un2, &u16);
  32. printf("&un.buf = %p, &un2.buf = %p\n", &un.buf, &un2.buf);
  33.  
  34.  
  35.  
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 5396KB
stdin
Standard input is empty
stdout
&a = 0x7ffe491f28f5, &b = 0x7ffe491f2911, &c = 0x7ffe491f2912
&d = 0x7ffe491f2914, &e = 0x7ffe491f2917, &f = 0x7ffe491f291b
&g = 0x7ffe491f2920, &h = 0x7ffe491f2926, &i = 0x7ffe491f292d
&j = 0x7ffe491f2935, &k = 0x7ffe491f293e
sizeof(my_union_t) = 12
&un = 0x7ffe491f28f8, &un2 = 0x7ffe491f2904, u16 = 0x7ffe491f28f6
&un.buf = 0x7ffe491f28f8, &un2.buf = 0x7ffe491f2904