Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, the key moment here is that the result of <code>++i</code> is an <em>lvalue</em>. And in order to participate in binary <code>+</code> that lvalue has to be converted to an rvalue by lvalue-to-rvalue conversion. Lvalue-to-rvalue conversion is basically an act of reading the variable <code>i</code> from memory.</p> <p>That means that the value of <code>++i</code> is supposed to be obtained <em>as if</em> it was read directly from <code>i</code>. That means that conceptually the new (incremented) value of <code>i</code> must be ready (must be physically stored in <code>i</code>) before the evaluation of binary <code>+</code> begins. </p> <p>This extra sequencing is what inadvertently made the behavior defined in this case.</p> <p>In C++03 there was no strict requirement to obtain the value of <code>++i</code> directly from <code>i</code>. The new value could have been predicted/precalulated as <code>i + 1</code> and used as an operand of binary <code>+</code> even before it was physically stored in the the actual <code>i</code>. Although it can be reasonably claimed that the requirement was implicitly there even in C++03 (and the fact that C++03 did not recognize its existence was a defect of C++03)</p> <hr> <p>In case of <code>i++</code>, the result is an <em>rvalue</em>. Since it is already an rvalue, there's no lvalue-to-rvalue conversion involved and there's absolutely no requirement to store it in <code>i</code> before we start evaluating the binary <code>+</code>.</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. 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