title: Portably safe to pass NULL/zero to dynamic_cast?
body: <p>Out of habit for checking null pointers, I have sometimes written:</p>
  
  <pre><code>MyClass * c = someBasePtr ? dynamic_cast&lt;MyClass*&gt;(someBasePtr) : 0;
  if (c) {...
  </code></pre>
  
  <p>In effect, checking for a null pointer before passing to dynamic cast, and also checking the return.</p>
  
  <p>I then read in the MSDN documentation </p>
  
  <blockquote>
    <p>A null pointer value is converted to
    the null pointer value of the
    destination type by dynamic_cast.</p>
  </blockquote>
  
  <p>It appears then that I could remove the ?: construct safely.  Is this C++ <em>portable</em>?</p>
  
  <p>Such that the new code would be</p>
  
  <pre><code>MyClass * c = dynamic_cast&lt;MyClass*&gt;(someBasePtr);
  if (c) {...
  </code></pre>
  
  <p>Of course presuming that <em>someBasePtr</em> is either null or valid, i.e. not <em>wild</em> pointing to garbage...</p>