This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Reordering of function calls - compiler bug or allowed by standard?
- From: John Fine <johnsfine at verizon dot net>
- To: jens dot kilian at verigy dot com
- Cc: gcc-help at gcc dot gnu dot org
- Date: Wed, 24 Sep 2008 09:00:46 -0400
- Subject: Re: Reordering of function calls - compiler bug or allowed by standard?
- References: <20080924062551.GA3183@socle119.verigy.net>
Jens Kilian wrote:
/* model internal state of address register */
int N;
Most of your problem can be dealt with by making N volatile and making
RD be or call a function (it could be inline so there is no extra overhead).
if (RD(42) == RD(23))
But that still wouldn't control which of RD(42) or RD(23) happens
first. Did you expect to control that?
The compiler can't resequence volatile accesses across "sequence points".
With RD as a macro, you have:
if ( (writeit(42), readit()) == (writeit(23), readit()) )
I'm think the comma is a sequence point between each writeit and the
corresponding readit, but I don't think you have any sequence point
between either readit an the non corresponding writeit. If RD were or
called an inline function, there would be plenty of sequence points
between either readit an the non corresponding writeit.