title: Am I misunderstanding __attribute__ ((packed)) in GCC?
body: <p>I am trying the following, with gcc on win32.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  struct st { char c; int x; } __attribute__ ((packed));
  
  int main() {
      printf("%d\n", sizeof(struct st));
      return 0;
  }
  </code></pre>
  
  <p>I would expect that the printed value is 5, but it's 8.</p>
  
  <p>With the following, however, I get 5.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #pragma pack(1)
  struct st { char c; int x; };
  
  int main() {
      printf("%d\n", sizeof(struct st));
      return 0;
  }
  </code></pre>
  
  <p>There must be something wrong in my program, but I can't see what.
  I have read <a href="https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Variable-Attributes.html" rel="nofollow">gcc's manual</a> and several questions on SO about this, and I'm still puzzled. Any hint?</p>
  
  <p>Also from the answers to these questions on SO, I understand that I should not use packed structs for <a href="https://en.wikipedia.org/wiki/Marshalling_%28computer_science%29" rel="nofollow">marshalling</a>, and I probably won't use it much, but I still would like to understand what I'm not able to see in such a short program.</p>
  
  <p>Note: the problem occurs with both gcc-4.9.2 and gcc-4.8.4.</p>