[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

pinskia at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Wed Oct 29 01:35:00 GMT 2008



------- 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



More information about the Gcc-bugs mailing list