Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Sequence points only define a <em>partial</em> ordering. In your case, you have (once overload resolution is done):</p> <pre><code>std::cout.operator&lt;&lt;( a++ ).operator&lt;&lt;( a ); </code></pre> <p>There is a sequence point between the <code>a++</code> and the first call to <code>std::ostream::operator&lt;&lt;</code>, and there is a sequence point between the second <code>a</code> and the second call to <code>std::ostream::operator&lt;&lt;</code>, but there is no sequence point between <code>a++</code> and <code>a</code>; the only ordering constraints are that <code>a++</code> be fully evaluated (including side effects) before the first call to <code>operator&lt;&lt;</code>, and that the second <code>a</code> be fully evaluated before the second call to <code>operator&lt;&lt;</code>. (There are also causual ordering constraints: the second call to <code>operator&lt;&lt;</code> cannot preced the first, since it requires the results of the first as an argument.) §5/4 (C++03) states:</p> <blockquote> Except where noted, the order of evaluation of operands of individual operators and subexpressions of individual expressions, and the order in which side effects take place, is unspecified. Between the previous and next sequence point a scalar object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be accessed only to determine the value to be stored. The requirements of this paragraph shall be met for each allowable ordering of the subexpressions of a full expression; otherwise the behavior is undefined. </blockquote> <p>One of the allowable orderings of your expression is <code>a++</code>, <code>a</code>, first call to <code>operator&lt;&lt;</code>, second call to <code>operator&lt;&lt;</code>; this modifies the stored value of <code>a</code> (<code>a++</code>), and accesses it other than to determine the new value (the second <code>a</code>), the behavior is undefined.</p>
 

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