title: Array of Bit_fields in C
body: <p>I've a flag of 8 bits in C and I want to access it bit by bit using bit-fields like this:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdint.h&gt;
  
  int main(void) {
      struct flags{
          uint8_t bits1:1;
          uint8_t bits2:1;
          uint8_t bits3:1;
          uint8_t bits4:1;
          uint8_t bits5:1;
          uint8_t bits6:1;
          uint8_t bits7:1;
          uint8_t bits8:1;
      };
      struct flags *my_flags;
      uint8_t x=6,i;
  
      my_flags=(struct flags *)&amp;x;
      printf("%u\t",my_flags-&gt;bits5);
      printf("%u\t",my_flags-&gt;bits6);
      printf("%u\t",my_flags-&gt;bits7);
      printf("%u\t",my_flags-&gt;bits8);
      printf("%u\t",my_flags-&gt;bits1);
      printf("%u\t",my_flags-&gt;bits2);
      printf("%u\t",my_flags-&gt;bits3);
      printf("%u\t",my_flags-&gt;bits4);
      return 0;
  }
  </code></pre>
  
  <p>and I get the expected output: <code>0   0   0   0   0   1   1   0</code>.</p>
  
  <p>But this is a bit too much coding.</p>
  
  <ol>
  <li>Isn't there something like array of bit-fields or any other workaround for it? (or)</li>
  <li>Is there anything like this in C <code>my_flags-&gt;bits_i</code> where <code>i</code> will be a counter in a loop?</li>
  </ol>
  
  <p>I know both are not there in C by default. But are there any alternatives to achieve the same?</p>