This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c/10143: Post increment doesn work more than once per statement
- From: Neil Booth <neil at daikokuya dot co dot uk>
- To: Nick Macdonald <macdonn at nortelnetworks dot com>
- Cc: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>,Falk Hueffner <falk dot hueffner at student dot uni-tuebingen dot de>,gcc-gnats at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org
- Date: Thu, 20 Mar 2003 00:08:04 +0000
- Subject: Re: c/10143: Post increment doesn work more than once per statement
- References: <Pine.LNX.4.33.0303191901280.5724-100000@kern.srcf.societies.cam.ac.uk> <3E78CAF5.8BB344D7@americasm01.nt.com>
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.