title: How to compare objects of POD types
body: <p>This example :</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  
  struct A
  {
      int  a;
      bool b;
  };
  
  bool foo( const A a1, const A a2 )
  {
      return ( 0 == std::memcmp( &amp;a1, &amp;a2, sizeof( A ) ) );
  }
  
  int main()
  {
      A a1 = A();
      a1.a = 5;a1.b = true;
      A a2 = A();
      a2.a = 5;a2.b = true;
  
      std::cout&lt;&lt;std::boolalpha &lt;&lt; foo( a1, a2 ) &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>is going to produce <code>false</code>, because of padding.</p>
  
  <p>I do not have access to the <code>foo</code> function, and I can not change the way the comparison is done.</p>
  
  <p>Assuming a <code>bool</code> occupies 1 byte (that is true on my system), if I change the <code>struct A</code> to this :</p>
  
  <pre><code>struct A
  {
    int a;
    bool b;
    char dummy[3];
  };
  </code></pre>
  
  <p>then it works fine on my system (the output is <code>true</code>).</p>
  
  <p>Is there anything else I could do to fix the above problem (get the <code>true</code> output)?</p>