Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, short-circuiting and evaluation order are required for operators <code>||</code> and <code>&amp;&amp;</code> in both C and C++ standards.</p> <p>C++ standard says (there should be an equivalent clause in the C standard):</p> <blockquote> <p><strong>1.9.18</strong></p> <p><em>In the evaluation of the following expressions</em></p> <pre><code>a &amp;&amp; b a || b a ? b : c a , b </code></pre> <p><em>using the built-in meaning of the operators in these expressions, <strong>there is a sequence point after the evaluation of the first expression</strong> (12).</em></p> </blockquote> <p>In C++ there is an extra trap: short-circuiting does <strong>NOT</strong> apply to types that overload operators <code>||</code> and <code>&amp;&amp;</code>.</p> <blockquote> <p><em>Footnote 12: The operators indicated in this paragraph are the built-in operators, as described in clause 5. When one of these operators is overloaded (clause 13) in a valid context, thus designating a user-defined operator function, the expression designates a function invocation, and the operands form an argument list, <strong>without an implied sequence point between them.</em></strong></p> </blockquote> <p>It is usually not recommended to overload these operators in C++ unless you have a very specific requirement. You can do it, but it may break expected behaviour in other people's code, especially if these operators are used indirectly via instantiating templates with the type overloading these operators.</p>
    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. 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.
 

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