This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/37947] p->count += inc(p); // value of p->count is wrong, if inc(p) not only returns an int but also increases p->counter
- From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 29 Oct 2008 01:34:26 -0000
- Subject: [Bug c/37947] p->count += inc(p); // value of p->count is wrong, if inc(p) not only returns an int but also increases p->counter
- References: <bug-37947-16874@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from pinskia at gcc dot gnu dot org 2008-10-29 01:34 -------
counter += inc(&counter);
That is undefined code as you access counter without a sequence point where you
assign it.
So it is valid for GCC to change the above to:
int tmp = counter;
tmp += inc(&counter);
counter = tmp;
Or
int tmp = inc(&counter);
counter += tmp;
The same thing happens with p->counter += inc(p);
except instead s/counter/p->counter/ and s/&counter/p/.
Thanks,
Andrew Pinski
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37947