title: typecast the return value of a function to an unrelated type of the same size
body: <p>Suppose type A and type B are of the same size, i.e. <code>sizeof(A) == sizeof(B)</code>, How can I re-interpret some memory containing B as A?</p>
  
  <p>What I want to do is:</p>
  
  <pre><code>B myFunction()
  {
       A  x;
  
       // do some operations here.
  
       // Solution 1: not working, since there is no such conversion function called 'B'.
       //    return  B(x);
  
       // Solution 2:
       return  *(B*)(&amp;x);       // should work.
  }
  </code></pre>
  
  <p>It seems that Solution 2 is working.  However, if the entity to be returned is not a variable like <code>x</code> above, but a function...  Say, I have a function <code>f2()</code> as below:</p>
  
  <pre><code>A f2()
  {
     ....
  }
  </code></pre>
  
  <p>in <code>myFunction()</code>, I want the return statement to use <code>f2()</code>:</p>
  
  <pre><code>     return  *(B*)(&amp; (f2()));    // definitely not working.
  </code></pre>
  
  <p>i.e. to interpret the return value of f2() as type B.</p>
  
  <p>It is apparent that the return value of a function does not have an address, and thus can not take the address operator <code>&amp;</code>.</p>
  
  <p>Then, how can I do that?</p>