On Friday, 28 March 2014 at 18:04:41 UTC, Frustrated wrote:
On Friday, 28 March 2014 at 16:54:49 UTC, Benjamin Thaut wrote:
I had a bug which came down to the following line today:
m_takeIndex = m_takeIndex++;
Actually this line does nothing. m_takeIndex remains at
exactly the same value as before (tested with dmd 2.065).
Can someone please explain why? And would be suitable to warn
about this, if it is correct behaviour?
Kind Regards
Benjamin Thaut
This should be invalid.
m_takeIndex++;
actually increments the variable.
m_takeIndex = m_takeIndex++; should do exactly the same.
Nope. Nope nope nope. That's not what postfix increment is.
That's why prefix increment exists.
Yeah, it might be an odd design (dates back to poor optimising
compilers and fast INC/DEC instructions apparently), but that's
how it is in C and how it is in D, by inheritance.