title: Why sizeof is different on linux and VS of 32bit process? even with "#pragma pack" and "-fpack-struct"
body: <pre><code>#include "stdio.h"
  
  #pragma pack(8)
  struct testSize {
      int a;  //size 4, alignment 8
      double b;//size 8, alignment 8
  };
  #pragma pack()
  
  int main(int argc, char** argv)
  {
      printf("sizeof testSize %d \n", sizeof(struct testSize));
      printf("sizeof int %d , sizeof double %d\n", sizeof(int), sizeof(double));
  
      return 0;
  }
  </code></pre>
  
  <p>The default max alignment of a struct is 8, and also we can set by <code>#pragma pack(8)</code> or <code>-fpack-struct=8</code>. But on 32bit process compiled with gcc, it doesn't work.</p>
  
  <p>On Linux (32): </p>
  
  <pre><code>$ gcc -m32 -fpack-struct=8 -o TestSize TestSize.c
  $ ./TestSize
  sizeof testSize 12
  sizeof int 4 , sizeof double 8
  </code></pre>
  
  <p>On VS (x86):</p>
  
  <pre><code>sizeof testSize 16
  sizeof int 4 , sizeof double 8
  </code></pre>
  
  <p>On linux, the alignment seems like 4, not 8. <a href="https://gcc.gnu.org/onlinedocs/gcc-4.4.4/gcc/Structure_002dPacking-Pragmas.html#Structure_002dPacking-Pragmas" rel="nofollow noreferrer">From the doc</a>, it's "For compatibility with Microsoft Windows compilers". </p>