title: Casting between unrelated congruent classes
body: <p>Suppose I have two classes with identical members from two different libraries:</p>
  
  <pre><code>namespace A {
    struct Point3D {
      float x,y,z;
    };
  }
  
  namespace B {
    struct Point3D {
      float x,y,z;
    };
  }
  </code></pre>
  
  <p>When I try cross-casting, it worked:</p>
  
  <pre><code>A::Point3D pa = {3,4,5};
  B::Point3D* pb = (B::Point3D*)&amp;pa;
  cout &lt;&lt; pb-&gt;x &lt;&lt; " " &lt;&lt; pb-&gt;y &lt;&lt; " " &lt;&lt; pb-&gt;z &lt;&lt; endl;
  </code></pre>
  
  <p>Under which circumstances is this guaranteed to work? Always? Please note that it would be highly undesirable to edit an external library to add an alignment pragma or something like that. I'm using g++ 4.3.2 on Ubuntu 8.10.</p>