title: What are the differences between #pragma pack(push, n)/#pragma pack(pop) and __attribute__((__packed__, aligned(n) )) on GCC?
body: <p>On GCC specifically (that is, compiling both with GCC), what are the differences between the way the following two work?</p>
  
  <pre><code>struct foo1 {
      char a;
      int b;
  } __attribute__((__packed__, aligned(n) ));
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>#pragma pack(push, n)
  struct foo2 {
      char a;
      int b;
  };
  #pragma pack(pop)
  </code></pre>
  
  <p>They <a href="http://coliru.stacked-crooked.com/a/b134364f7e775f87">appear to behave differently</a>:</p>
  
  <pre><code>foo1 f1;
  foo2 f2;
  
  int&amp; i1 = f1.b; // ok
  int&amp; i2 = f2.b; // cannot bind packed field 'f2.foo2::b' to 'int&amp;'
  </code></pre>
  
  <p>Why is there an error in one yet not the other? Are the memory layouts the same, at least? </p>