Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, it mandates that (both evaluation order and short circuit). In your example if all functions return true, the order of the calls are strictly from functionA then functionB and then functionC. Used for this like</p> <pre><code>if(ptr &amp;&amp; ptr-&gt;value) { ... } </code></pre> <p>Same for the comma operator:</p> <pre><code>// calls a, then b and evaluates to the value returned by b // which is used to initialize c int c = (a(), b()); </code></pre> <p>One says between the left and right operand of <code>&amp;&amp;</code>, <code>||</code>, <code>,</code> and between the first and second/third operand of <code>?:</code> (conditional operator) is a "sequence point". Any side effects are evaluated completely before that point. So, this is safe:</p> <pre><code>int a = 0; int b = (a++, a); // b initialized with 1, and a is 1 </code></pre> <p>Note that the comma operator is not to be confused with the syntactical comma used to separate things:</p> <pre><code>// order of calls to a and b is unspecified! function(a(), b()); </code></pre> <p>The C++ Standard says in <code>5.14/1</code>:</p> <blockquote> <p>The &amp;&amp; operator groups left-to-right. The operands are both implicitly converted to type bool (clause 4). The result is true if both operands are true and false otherwise. Unlike &amp;, &amp;&amp; guarantees left-to-right evaluation: the second operand is not evaluated if the first operand is false.</p> </blockquote> <p>And in <code>5.15/1</code>:</p> <blockquote> <p>The || operator groups left-to-right. The operands are both implicitly converted to bool (clause 4). It returns true if either of its operands is true, and false otherwise. Unlike |, || guarantees left-to-right evaluation; moreover, the second operand is not evaluated if the first operand evaluates to true.</p> </blockquote> <p>It says for both next to those:</p> <blockquote> <p>The result is a bool. All side effects of the first expression except for destruction of temporaries (12.2) happen before the second expression is evaluated.</p> </blockquote> <p>In addition to that, <code>1.9/18</code> says</p> <blockquote> <p>In the evaluation of each of the expressions</p> <ul> <li><code>a &amp;&amp; b</code></li> <li><code>a || b</code></li> <li><code>a ? b : C</code></li> <li><code>a , b</code></li> </ul> <p>using the built-in meaning of the operators in these expressions (5.14, 5.15, 5.16, 5.18), there is a sequence point after the evaluation of the first expression.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload