title: Is calling a function on a NULL pointer undefined?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2474018/when-does-invoking-a-member-function-on-a-null-instance-result-in-undefined-beha">When does invoking a member function on a null instance result in undefined behavior?</a><br>
    <a href="https://stackoverflow.com/questions/2727834/c-standard-dereferencing-null-pointer-to-get-a-reference">C++ standard: dereferencing NULL pointer to get a reference?</a>  </p>
  </blockquote>
  
  
  
  <p>Say I have the class:</p>
  
  <pre><code>class A
  {
  public:
     void foo() { cout &lt;&lt; "foo"; }
  };
  </code></pre>
  
  <p>and call foo like so:</p>
  
  <pre><code>A* a = NULL;
  a-&gt;foo();
  </code></pre>
  
  <p>I suspect this invokes undefined behavior, since it's equivalent to <code>(*a).foo()</code> (or is it?), and dereferencing a <code>NULL</code> <strong>is</strong> UB, but I can't find the reference. Can anyone help me out? Or is it defined? </p>
  
  <p>No, the function is not <code>virtual</code>. No, I'm not accessing any members.</p>
  
  <p>EDIT: I voted to close this question but will not delete it as I couldn't find the duplicate myself, and I suspect this title might be easier to find by others.</p>