title: Clang and Visual C++ struct alignment compatibility issues
body: <p>We're having a problem struct memory packing and alignment. </p>
  
  <p>Android is not honoring the #pragma pack(push, &lt;n&gt;) which is in several hundred places in our code base. This is causes segfault. </p>
  
  <p>The Android Clang compiler requires an __ attribute __ decorator on the struct or class, for example:</p>
  
  <pre><code>struct __attribute__((packed, aligned(8))) Test
  {
      char a;
      char b;
      double d;
  };
  </code></pre>
  
  <p>As opposed to this for Visual C++ that honors the pragma:</p>
  
  <pre><code>#pragma pack(push, 8)
  struct  Test
  {
         char a;
         char b;
         double d;
  };
  #pragma pack(pop)
  </code></pre>
  
  <p>Since the use of #pragma pack is so widespread, it will be a time-consuming task to fix.</p>
  
  <p>We tried using the -mms-bitfields compiler flag which sets the default structure layout to be compatible with the Microsoft compiler standard (i.e. it honors the #pragma pack). However this only works for trivial structs and not classes with base classes or virtual functions. We get the following error with these type of classes.</p>
  
  <p>“error : ms_struct may not produce Microsoft-compatible layouts for classes with base classes or virtual functions [-Wincompatible-ms-struct]”</p>
  
  <p>How can we mitigate this issue - is there any workaround to make #pragma pack work for non-trivial structs/classes other than to go over all the classes/struct between push and pop pragmas and add the packed attribute?</p>
  
  <p>Thanks</p>