As you know, this goes through zero:
while (x-- > 0) { /* also known as x --> 0 */ printf("x = %d\n", x); }
But x = x--gives undefined behavior .
x = x--
Both examples need some “return” to a value x--that I don’t think. How can it be that is x-- > 0determined, but is x = x--not?
x--
x-- > 0
Because in x = x--you change the value twice xwithout an intermediate point in the sequence. Thus, the order of operations is not defined. The x-- > 0value xchanges once, and it is clearly defined that the result of the evaluation x--will be the value xbefore decrement.
x
, "" x--, ". -, , . -, , , undefined x = x--.
x = x-- undefined, x . "" " ".
x = x-- , , undefined undefined . . postfix --. x . undefined de jure.
--
, x 5, x 4 ( ) 5 ( ) . , x 4 5 .
5
4
(, 4 vs 5) UB. , , , undefined, , .
, . . : http://en.wikipedia.org/wiki/Sequence_point
= , , x , x.
=
while x-- > 0, x--, , undefined, x .
- , .
fooobar.com/questions/2129/.... , = , , , :
load i to reg increment i assign reg to i => i has previous value of i load i to reg assign reg to i increment i => i has value of previous value of i + 1
In general: avoid assigning (this includes modifying pre / post ++ / -) to the same variable twice in the same expression.