Re: Is i = i++; bad style?
- From: Robert Gamble <rgamble99@xxxxxxxxx>
- Date: Fri, 06 Jul 2007 03:43:47 -0000
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
.
- Follow-Ups:
- Re: Is i = i++; bad style?
- From: Richard Heathfield
- Re: Is i = i++; bad style?
- References:
- Is i = i++; bad style?
- From: lovecreatesbea...@xxxxxxxxx
- Re: Is i = i++; bad style?
- From: lovecreatesbea...@xxxxxxxxx
- Is i = i++; bad style?
- Prev by Date: Re: Is i = i++; bad style?
- Next by Date: Style question: #include
- Previous by thread: Re: Is i = i++; bad style?
- Next by thread: Re: Is i = i++; bad style?
- Index(es):
Relevant Pages
|