title: Inaccurate size of a struct with bit fields in my book
body: <p>I'm studying the basics of the C language. I arrived at the chapter of structures with bit fields. The book shows an example of a struct with two different types of data: various bools and various unsigned ints.</p>
  
  <p>The book declares that the structure has a size of 16 bits and that without using padding the structure would measure 10 bits.</p>
  
  <p>This is the structure that the book uses in the example:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdbool.h&gt;
  
  struct test{
  
         bool opaque                 : 1;
         unsigned int fill_color     : 3;
         unsigned int                : 4;
         bool show_border            : 1;
         unsigned int border_color   : 3;
         unsigned int border_style   : 2;
         unsigned int                : 2;
  };
  
  int main(void)
  {
         struct test Test;
  
         printf("%zu\n", sizeof(Test));
  
         return 0;
  }
  </code></pre>
  
  <p>Why on my compiler instead does the exact same structure measure 16 <strong>bytes</strong> (rather than bits) with padding and 16 bytes without padding?</p>
  
  <p>I'm using </p>
  
  <pre><code>GCC (tdm-1) 4.9.2 compiler;
  Code::Blocks as IDE.
  Windows 7 64 Bit
  Intel CPU 64 bit
  </code></pre>
  
  <p>This is result I'm getting:</p>
  
  <p><a href="https://i.stack.imgur.com/Pd31j.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Pd31j.png" alt="enter image description here"></a></p>
  
  <p>Here is a picture of the page where the example is:</p>
  
  <p><a href="https://i.stack.imgur.com/QwkFi.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/QwkFi.jpg" alt="enter image description here"></a></p>