fork download
  1. #include <stdio.h>
  2.  
  3. volatile union{
  4. unsigned char Table_ALL[2];
  5. struct{
  6. union {
  7. unsigned char Byte ;
  8. struct {
  9. unsigned char C1_1:1;
  10. unsigned char C1_2:1;
  11. unsigned char C1_3:1;
  12. unsigned char C1_4:1;
  13. unsigned char C1_5:1;
  14. unsigned char C1_6:1;
  15. unsigned char C1_7:1;
  16. unsigned char C1_8:1;
  17. }BIT;
  18. } S1_C1;
  19.  
  20. union {
  21. unsigned char Byte ;
  22. struct {
  23. unsigned char C2_1:1;
  24. unsigned char C2_2:1;
  25. unsigned char C2_3:1;
  26. unsigned char C2_4:1;
  27. unsigned char C2_5:1;
  28. unsigned char C2_6:1;
  29. unsigned char C2_7:1;
  30. unsigned char C2_8:1;
  31. }BIT;
  32. } S1_C2;
  33. }S1;
  34. }Table;
  35.  
  36.  
  37. int main(void) {
  38. // your code goes here
  39. printf("Table_ALL[0] = %d\n", Table.Table_ALL[0]);
  40. printf("Table_ALL[1] = %d\n", Table.Table_ALL[1]);
  41.  
  42. printf("Write 1 to S1_C1.Byte\n");
  43. Table.S1.S1_C1.Byte = 1;
  44. printf("S1.S1_C1.Byte = %d\n", Table.S1.S1_C1.Byte);
  45. printf("S1.S1_C2.Byte = %d\n", Table.S1.S1_C2.Byte);
  46.  
  47. printf("Table_ALL[0] = %d\n", Table.Table_ALL[0]);
  48. printf("Table_ALL[1] = %d\n", Table.Table_ALL[1]);
  49.  
  50. printf("Write 2 to S1_C2.Byte\n");
  51. Table.S1.S1_C2.Byte = 2;
  52. printf("S1.S1_C1.Byte = %d\n", Table.S1.S1_C1.Byte);
  53. printf("S1.S1_C2.Byte = %d\n", Table.S1.S1_C2.Byte);
  54.  
  55. printf("Table_ALL[0] = %d\n", Table.Table_ALL[0]);
  56. printf("Table_ALL[1] = %d\n", Table.Table_ALL[1]);
  57. return 0;
  58. }
Success #stdin #stdout 0s 4364KB
stdin
Standard input is empty
stdout
Table_ALL[0] = 0
Table_ALL[1] = 0
Write 1 to S1_C1.Byte
S1.S1_C1.Byte = 1
S1.S1_C2.Byte = 0
Table_ALL[0] = 1
Table_ALL[1] = 0
Write 2 to S1_C2.Byte
S1.S1_C1.Byte = 1
S1.S1_C2.Byte = 2
Table_ALL[0] = 1
Table_ALL[1] = 2