title: Order of fields when using a bit field in C
body: <p>I have a struct of the following type</p>
  
  <pre><code>typedef struct
  {
  unsigned int a : 8;
  unsigned int b : 6;
  unsigned int c : 2;
  }x, *ptr;
  </code></pre>
  
  <p>What i would like to do, is change the value of field c.</p>
  
  <p>I do something like the following</p>
  
  <pre><code>x structure = { 0 };
  x-&gt;c = 1;
  </code></pre>
  
  <p>When I look at the memory map, I expect to find <em>00 01</em>, but instead I find <em>00 40</em>.
  It looks like when arranging the second byte, it puts <em>c</em> field in the lowest bits and <em>b</em> field in the highest bits. I've seen this on both GCC and Windows compilers.</p>
  
  <p>For now, what I do is the following, which is working OK.</p>
  
  <pre><code>unsigned char ptr2 = (unsigned char*) ptr
  *(ptr2 + 1)  &amp;= 0xFC
  *(ptr2 + 1)  |= 0x01
  </code></pre>
  
  <p>Am I looking at the memory map wrong?
  Thank you for your help.</p>