c/10143: Post increment doesn work more than once per statement

Neil Booth neil@daikokuya.co.uk
Thu Mar 20 01:07:00 GMT 2003


Nick Macdonald wrote:-

> I was just trying to make the product better...  I feel the answer of
> "not a bug" to be a bit pedantic...  sure, technically it may not be a
> bug...  however, logically, the current behaviour is less than stellar
> and it should be addressed to make post and pre increment behave more or
> less similarly...  I have learned a valuable lesson from all this, and I

Things aren't that clearcut - effectively, the compiler passes the
code to the optimizer with a set of restrictions indicating what the
optimizer can and cannot assume.  Because of guarantees afforded by the
standard, the optimizer is given pretty free reign, and munges your code.
But that's only because it's wrong.  It's not a matter of treating a or
b consistently; just consider it a fluke that you observed the result
you did.  If you move a line of code you might see a different result,
or GCC in 2 months time might, for any of a million reasons, decide to
optimize it differently.

Now, -Wsequence-point should have warned, but its algorithm is based on
GCC trees, so consider me unsurprised at its fragility.  None of this
existed in 2.95, but it does in 3.2.

Neil.



More information about the Gcc-bugs mailing list