C++ 'AND' evaluation - standard guaranteed?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/7580945/safety-concerns-about-short-circuit-evaluation">Safety concerns about short circuit evaluation</a>  </p>
</blockquote>



<p>What does the standard say about evaluating <code>&amp;&amp;</code> expressions - does it guarantee that evaluation of parameters will stop at the first <code>false</code>?</p>

<p>E.g.:</p>

<pre><code>Foo* p;
//....
if ( p &amp;&amp; p-&gt;f() )
{
    //do something
}
</code></pre>

<p>is the <code>f()</code> guaranteed not to be called if <code>p == NULL</code>?</p>

<p>Also, is the order of evaluation guaranteed to be the order of appearence in the clause?</p>

<p>Might the optimizer change something like:</p>

<pre><code>int x;
Foo* p;
//...
if ( p-&gt;doSomethingReallyExpensive() &amp;&amp; x == 3 )
{
    //....
}
</code></pre>

<p>to a form where it evaluates <code>x==3</code> first? Or will it always execute the really expensive function first?</p>

<p>I know that on most compilers (probably all) evaluation stops after the first <code>false</code> is encountered, but what does the standard say about it?</p>
