title: #pragma pack() with push and pop vs unpack
body: <p>I have this sample program below</p>
  
  <pre><code>#include &lt;stdio.h&gt;                              
  #include &lt;stdlib.h&gt;
  
  #pragma pack(push)
  #pragma pack(1)
  typedef struct{
    char a;
    int b;
    char c;
  }st_a;
  #pragma pack(pop)
  
  typedef struct{
    char a;
    int b;
    char c;
  }st_b;
  
  
  int main()
  {
    printf("size of struct a %zd \n",sizeof(st_a));
    printf("size of struct b %zd \n",sizeof(st_b));
  
    return 0;
  }
  </code></pre>
  
  <p>Output of the above program is</p>
  
  <pre><code>size of struct a 6 
  size of struct b 12 
  </code></pre>
  
  <p>Now if I change the struct declaration as below:</p>
  
  <pre><code>#pragma pack(1)
  typedef struct{
    char a;
    int b;
    char c;
  }st_a;
  #pragma unpack()
  </code></pre>
  
  <p>Output of the program is</p>
  
  <pre><code>size of struct a 6 
  size of struct b 6 
  </code></pre>
  
  <p>Why is this difference in the behaviour? My understanding was that both structure declarations are doing the same thing.</p>
  
  <p>I am running this on my MBP.</p>
  
  <pre><code>$gcc --version 
  
  Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
  Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
  Target: x86_64-apple-darwin14.4.0
  Thread model: posix
  </code></pre>