title: Why is it allowed to cast a pointer to a reference?
body: <p>Originally being the topic of <a href="https://stackoverflow.com/questions/5923702/casting-an-object-to-a-reference">this question</a>, it emerged that the OP just overlooked the dereference. Meanwhile, <a href="https://stackoverflow.com/questions/5923702/casting-an-object-to-a-reference/5923735#5923735">this answer</a> got me and some others thinking - why is it allowed to cast a pointer to a reference with a C-style cast or <code>reinterpret_cast</code>?</p>
  
  <pre><code>int main() {
      char  c  = 'A';
      char* pc = &amp;c;
  
      char&amp; c1 = (char&amp;)pc;
      char&amp; c2 = reinterpret_cast&lt;char&amp;&gt;(pc);
  }
  </code></pre>
  
  <p>The above code compiles without any warning or error (regarding the cast) on Visual Studio while GCC will only give you a warning, as shown <a href="http://ideone.com/4eEwU" rel="noreferrer">here</a>.</p>
  
  <hr>
  
  <p>My first thought was that the pointer somehow automagically gets dereferenced (I work with MSVC normally, so I didn't get the warning GCC shows), and tried the following:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main() {
      char  c  = 'A';
      char* pc = &amp;c;
  
      char&amp; c1 = (char&amp;)pc;
      std::cout &lt;&lt; *pc &lt;&lt; "\n";
  
      c1 = 'B';
      std::cout &lt;&lt; *pc &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>With the very interesting output shown <a href="http://ideone.com/YV4O5" rel="noreferrer">here</a>. So it seems that you <em>are</em> accessing the pointed-to variable, but at the same time, you are not.  </p>
  
  <p>Ideas? Explanations? Standard quotes?</p>