Re: Is i = i++; bad style?



On Jul 5, 11:28 pm, "lovecreatesbea...@xxxxxxxxx"
<lovecreatesbea...@xxxxxxxxx> wrote:
On Jul 6, 11:25 am, "lovecreatesbea...@xxxxxxxxx"

<lovecreatesbea...@xxxxxxxxx> wrote:
i = i++;

The gcc gives out a warning on this line of code, saying "warning:
operation on `i' may be undefined".

But I think, at the end of the execution of the statement, the
variable i is eventually increased by one, am I right?

As a part of a compound expression, i = i++ (an expression, no
semocolon followed) may be undefined value, right?

It is undefined both as part of a larger expression and as a
standalone expression. 9899:1999 §6.5p2 reads:

"Between the previous and next sequence point an object shall have its
stored value
modified at most once by the evaluation of an expression. Furthermore,
the prior value
shall be read only to determine the value to be stored."

Assignment does not introduce a sequence point so i is modified twice
without an intervening sequence point, once by the ++ operator and
once by the assignment. Violation of a "shall" outside of a
constraint (as is the case here) causes undefined behavior. See also
<http://www.c-faq.com/> question 3.3.

Robert Gamble

.



Relevant Pages

  • Re: Must an expression be evaluated before its value is used?
    ... this is not a sequence point. ... The evaluation dependency has a consequence of ... seperate the assignment of 5 to x from the assignment of 11 to x. ... comma operator without first evaluating it's second operand. ...
    (comp.std.c)
  • Re: Decoding RNA codons: fastest method challenge
    ... this decoding application as required by the assignment is pretty much ... sequence is known to be Prokaryotic, ... you have to check for sequence context surrounding the ... initiator AUG to aid in discrimiting it (again, ...
    (comp.lang.pascal.borland)
  • Re: Best way to override AllowNull in a schema?
    ... the sequence is tied to the column. ... In Oracle, it can't get that information automatically. ... number that violates the uniqueness constraint of the table. ... autoincrement column has autogenerated - which, logically, the system ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: x=(x=5,11)
    ... You're introducing a sequence point between the right-hand side of the ... assignment operator and the assignment itself. ... define such a sequence point between the evaluation of the arguments to ... the value of the right operand is converted ...
    (comp.lang.c)
  • Re: x=(x=5,11)
    ... convert it to the type of the assignment expression without evaluting ... Sequence points define a partial ordering. ... "The order of evaluation of the function designator, ... made to modify the result of a comma operator or to access it after the ...
    (comp.lang.c)