Ruben Mikkonen <> writes:
[...]
> I think that a = a++ means the following: first a = a, and then you
> increase a by 1. So in my opinion, the statement should equal to a =
> a+1, or a++.
[...]
This is not a matter of opinion. As has been stated countless times,
the behavior is undefined -- not just the result of the expression,
or the values assigned to a, but the behavior of any program that
evaluates that expression. It can do exactly what you expect it
to do, it can crash your program, it can reformat your hard drive.
What "a = a++" really means is that the person who wrote it
does not understand C well enough, and has not read the FAQ at
<http://c-faq.com>. (Both problems are curable).
Whatever you intended to do, there's certainly a better way to
express it. If you just want to increment a, just write "a++";
that already assigns the new value to a, so there's no need for an
assignment operator in addition to that. The "++" operator is not
just a fancy way of writing "+ 1".
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"