Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Edit: This answer is incorrect for the updated question, it applies to the question as originally stated.</strong></p> <p><code>(i++)++</code> shouldn't work with either gcc or g++, whether or not they are parsing the file as C or C++ in both languages postfix increment requires an <em>lvalue</em> as an operand and the result is an <em>rvalue</em>. </p> <p>(Note that <em>rvalue</em> is only used formally in C++. In C the results of expressions are either explicitly <em>lvalues</em> or they're just not <em>lvalues</em>. The term <em>rvalue</em> isn't used in the normative text of the C standard at all.)</p> <p>Simplisticly, an <em>lvalue</em> is an expression that refers to an object, i.e. conceptually a region of storage somewhere. A modifiable <em>lvalue</em> is something that it is valid to assign to so can appear on the <em>left</em> hand side of an assignment expression.</p> <p>An <em>rvalue</em> is just a value, something that you can assign a modifiable <em>lvalue</em> from, but not something that you can assign to. It can only appear on the <em>right</em> side of an assignment expression.</p> <p><code>g++</code> gives me the error: <code>lvalue required as increment operand</code>.</p> <p>Prefix increment (and decrement) are slightly different. In C++ the result of a prefix increment is explicitly an <em>lvalue</em> (5.3.2/1 [expr.pre.incr]); in C it is explicitly not an <em>lvalue</em> (6.5.3.1 states that ++E is equivalent to (E+=1); 6.5.16 says that the result of any assignment is not an lvalue).</p> <p><code>(++i)++</code> is, therefore, semantically correct only in C++, however it has <em>undefined behaviour</em> because you are storing a value to an object twice without an intervening <em>sequence point</em>.</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