title: G++ object model
body: <p>Today i read the &lt;>.i encountered a problem.as the book says, </p>
  
  <pre><code>class Concrete1 {
  public:
  int val;
  char bit1;
  };
  
  class Concrete2 : public Concrete1 {
  public:
  char bit2;
  };
  
  class Concrete3 : public Concrete2 {
  public:
  char bit3;
  };
  </code></pre>
  
  <p>when i run the code in mingw g++, the space of the three classes are 8, 12, 12.But when i run the code in vs2012, the space of the three classes are 8, 12, 16. of cource, the code in vs2012 is with no problem.But for the space in g++, i have some questions,and i try to write a sample code to see whether a problem. the sample code as follows :</p>
  
  <pre><code>int main(void)
  {
      Concrete2 con2;
      memset(&amp;con2, 0, sizeof(con2));
      Concrete3  con3;
      con3.val = 3;
      con3.bit2 =  4;
      con3.bit3 = 5;
      Concrete2* con_ptr2 = &amp;con2;
      Concrete2* con_ptr3 = &amp;con3;
      *con_ptr3 = *con_ptr2;
      cout &lt;&lt; con3.bit3&lt;&lt; endl;
      cout &lt;&lt; sizeof(Concrete1) &lt;&lt; endl;
      cout &lt;&lt; sizeof(Concrete2) &lt;&lt; endl;
      cout &lt;&lt; sizeof(Concrete3) &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>and for the object model in g++, the code is with no problem.why after the code "*con_ptr3 = *con_ptr2;", the con3.bit3 is 5 not 0?
  can anyone help me ?</p>