fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <inttypes.h>
  4.  
  5. typedef struct atomic_flags {
  6. unsigned int flags1 : 2;
  7. unsigned int flags2 : 2;
  8. unsigned int flags3 : 2;
  9. unsigned int flags4 : 2;
  10. unsigned int flags5 : 8;
  11. unsigned int reserved : 16;
  12. }atomic_flags;
  13.  
  14. union data {
  15. atomic_flags i;
  16. uint32_t q;
  17. } data;
  18.  
  19.  
  20.  
  21. int main() {
  22. union data test1;
  23. union data test2;
  24.  
  25. test1.i.flags1 = 1;
  26. test1.i.flags2 = 2;
  27. test1.i.flags3 = 3;
  28. test1.i.flags4 = 2;
  29. test1.i.flags5 = 241;
  30. test1.i.reserved = 1337;
  31.  
  32. printf("%u\n", test1.q);
  33.  
  34. __atomic_store_n(&test2.q, test1.q, __ATOMIC_SEQ_CST);
  35.  
  36. printf("test1 flags1: %u\n", test1.i.flags1);
  37. printf("test1 flags2: %u\n", test1.i.flags2);
  38. printf("test1 flags3: %u\n", test1.i.flags3);
  39. printf("test1 flags4: %u\n", test1.i.flags4);
  40. printf("test1 flags5: %u\n", test1.i.flags5);
  41. printf("test1 reserved: %u\n", test1.i.reserved);
  42.  
  43. printf("test2 flags1: %u\n", test2.i.flags1);
  44. printf("test2 flags2: %u\n", test2.i.flags2);
  45. printf("test2 flags3: %u\n", test2.i.flags3);
  46. printf("test2 flags4: %u\n", test2.i.flags4);
  47. printf("test2 flags5: %u\n", test2.i.flags5);
  48. printf("test2 reserved: %u\n", test2.i.reserved);
  49.  
  50. return 0;
  51.  
  52. }
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
87683513
test1 flags1: 1
test1 flags2: 2
test1 flags3: 3
test1 flags4: 2
test1 flags5: 241
test1 reserved: 1337
test2 flags1: 1
test2 flags2: 2
test2 flags3: 3
test2 flags4: 2
test2 flags5: 241
test2 reserved: 1337