title: Why does padding have to be a power of two?
body: <p>I am doing some sample programs to explore C and would like to know why structure padding can be done in power of two only.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #pragma pack(push, 3)
  
  union aaaa
  {
  
     struct bbb
     {
        int a;
        double b;
        char c;
     }xx;
  
     float f;
  };
  
  #pragma pack(pop)
  
  int main()
  {
  
  printf("\n Size: %d", sizeof(union aaaa));
  
  return 0;
  }
  </code></pre>
  
  <p>While compiling </p>
  
  <pre><code>warning: alignment must be a small power of two, not 3 [-Wpragmas]
  warning: #pragma pack (pop) encountered without matching #pragma pack (push) [-Wpragmas]
  </code></pre>
  
  <p>It seems #pragma has no effect. Output is 24 only. i.e 4 byte aligned. </p>