Python Success stories

Istvan Albert istvan.albert at gmail.com
Wed Apr 23 21:56:27 EDT 2008


On Apr 23, 2:08 pm, Bob Woodham <wood... at cs.ubc.ca> wrote:

> x = x++;
>
> has unspecified behaviour in C.  That is, it is not specified
> whether the value of x after execution of the statement is the
> old value of x or one plus the old value of x.

unspecified means that the result could be anything: old value, old
value+1, -2993882, "trallalla", core dump, stack overflow etc...

in Java the behavior is specified, but many might find the result
counterintuitive:

int x = 0;
x = x++;
System.out.println(x);

prints 0, if I recall it correctly the ++ mutates after the assignment
takes place, therefore it increments the old value that then summarily
discarded.

i.





More information about the Python-list mailing list