Valid use of reinterpret_cast?
<p>Empirically the following works (gcc and VC++), but is it valid and portable code?</p>

<pre><code>typedef struct 
{
    int w[2];
} A;

struct B
{
    int blah[2];
};

void my_func(B b)
{
    using namespace std;
    cout &lt;&lt; b.blah[0] &lt;&lt; b.blah[1] &lt;&lt; endl;
}

int main(int argc, char* argv[])
{

    using namespace std;

    A a;
    a.w[0] = 1;
    a.w[1] = 2;

    cout &lt;&lt; a.w[0] &lt;&lt; a.w[1] &lt;&lt; endl;

    // my_func(a);                     // compiler error, as expected
    my_func(reinterpret_cast&lt;B&amp;&gt;(a));  // reinterpret, magic?
    my_func(  *(B*)(&amp;a) );             // is this equivalent? 

    return 0;
}
// Output:
// 12
// 12
// 12
</code></pre>

<ul>
<li>Is the reinterpret_cast valid? </li>
<li>Is the C-style cast equivalent? </li>
<li>Where  the intention is to have the bits located at <code>&amp;a</code> interpreted as a
type B, is this a valid / the best approach?</li>
</ul>

<p>(Off topic: For those that want to know <em>why</em> I'm trying to do this, I'm dealing with two C libraries that want 128 bits of memory, and use structs with different internal names - much like the structs in my example. I don't want memcopy, and I don't want to hack around in the 3rd party code.)</p>
