This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/33270] Wrong evaluation
- From: "raeburn at raeburn dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 31 Aug 2007 19:04:47 -0000
- Subject: [Bug c/33270] Wrong evaluation
- References: <bug-33270-15049@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from raeburn at raeburn dot org 2007-08-31 19:04 -------
Subject: Re: New: Wrong evaluation
On Aug 31, 2007, at 11:05, tim dot bruylants at vub dot ac dot be wrote:
> The following code generates a "1" with gcc-4.1 and generates a "2"
> with a lot
> of other compilers (Visual Studio, gcc-3.2, ...). I have read the
> non-bugs
> section on http://gcc.gnu.org/bugs.html (also bug 11751) and I have
> read about
> "sequence points" on http://c-faq.com/expr/seqpoints.html. Still I
> feel that
> this is really a bug rather than a non-bug as in the many examples.
> Why?
> Because a function call is also a sequence point.
> (*p_a) += inca_and_ret1(p_a);
> The function call to inca_and_ret1 is a sequence point, this the
> value pointed
> to by p_a should be correct after the call. And then the expression
> "(*p_a) +=
> <return value>" should be evaluated (I think).
The sequence point at the function call means that side-effects in
the argument list have to be completed before the execution of the
function body starts. It doesn't force sequencing on other parts of
the expression containing the call, specifically when the old value
of the left-hand side of the "+=" would be read (or when the address
is computed, if inca_and_ret1 could modify the pointer p_a itself).
Ken
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33270