Re: x=(x=5,11)
- From: Barry Schwarz <schwarzb@xxxxxxxxx>
- Date: Thu, 22 Jun 2006 20:37:14 -0700
On 22 Jun 2006 00:45:17 -0700, google@xxxxxxxxxxxxx wrote:
Barry Schwarz wrote:
On 21 Jun 2006 02:01:21 -0700, google@xxxxxxxxxxxxx wrote:
Barry Schwarz wrote:
<snip and summarize thus>
((*f(0))++, (*f(1))++) + ((*f(2))++, (*f(3))++)
<snip>
I agree that the standard is ambiguous about this (which is where we
came in on this discussion anyway) but I believe that the _intent_ of
the standard is that
(*f())++ + (*f())++ has undefined behaviour because a _valid_
optimization for a compiler that can see that f() always returns the
same pointer is:
But the standard is not ambiguous at all. There is a sequence point
before each function call and all side effects must be complete at
that point. Optimizations are required to behave "as if" all
requirements are satisfied.
g=f(); (*g)++ + (*g)++;
This was a red herring when it first entered the conversation and is
still a red herring.
i.e. the sequence points before and after the calls to f() only
constrain the side effects that occur in f() itself.
Where did you invent that from? There is no such thing as a partial
sequence point. Which ever call to f() is evaluated second is
guaranteed that all side effects of any previous evaluation are
complete.
<snip>
So
S, f(), S, f(), S, inc, inc, S
is allowed.
This is subtly different from the subject line. In that case I think
the standard requires the assignment of 5 to x before the 11 is
evaluated (and so assigned to x) but I don't think the standard
_requires_ that the assignment of 11 to x starts _after_ the assignment
of 5 to x.
Evaluations never cross sequence points. The whole purpose ofYes. But there is confusion when it comes to sub-expressions that
sequence points is to insure that the evaluation is complete.
include sequence points. How much to they constrain things?
A sequence point is a sequence point. All side effects are complete.
This is one valid interpretation. A second is that the sequence points
What we are really interested in is whether the standard allows the
increment of f(1)++ to start before f(2) is called but to not complete
until the end of the full expression.
The standard guarantees that all side effects are complete prior to
the sequence point. Since there is a sequence point prior to the call
to f(2), the increment must be complete.
on the RHS have no effect on the LHS whatsoever and vice versa. A third
interpretation is that the sequence points on the RHS require that no
side effects are _still_ in progress on the LHS but do not otherwise
constrain when the side effects on the LHS can occur.
Only for some strange definition of the word all.
I would expect that it's actually the third interpretation that the
standard authors intended but it doesn't actually sound as reasonable
as either the first or second option when phrased as above.
Dream on.
consider g++ + f(); and (g=g+1) + f(); and (g=5) + f(); where f()
modifies g. Do these have defined or undefined behaviour?
It is still a red herring.
Since evaluating g in its many forms does not involve a sequence
point, this is nothing but a red herring.
huh? there's a sequence point both before and after the call to f() in
each of these therefore there is a sequence point between the
modifications of g.
Actually, the standard only talks about a sequence point at the return
from a *library* function. But you make my case for me.
I think these are interesting because one example I gave where the
subject line expression could give undefined results is where the
hardware only has the ability to flip bits so a write requires a read
first. For (g=g+1) + f(); clearly we can have:
read g
call f
add 1 to the g we read
write new g
Now if my hardware requires a read before write, does the standard
require a second read before the write in the above or is it legitimate
to reuse the first read? I think the standard should require that
second read. I'm not convinced it does.
There are lots of situations where it becomes murky. I am only
addressing the case described at the top of this message with four
calls to f.
Remove del for email
.
- References:
- Re: x=(x=5,11)
- From: Barry Schwarz
- Re: x=(x=5,11)
- From: Barry Schwarz
- Re: x=(x=5,11)
- From: google
- Re: x=(x=5,11)
- From: Barry Schwarz
- Re: x=(x=5,11)
- From: google
- Re: x=(x=5,11)
- Prev by Date: Re: sizeof
- Next by Date: Re: Wrong output - eliminate spaces in sentence.
- Previous by thread: Re: x=(x=5,11)
- Next by thread: Re: x=(x=5,11)
- Index(es):
Relevant Pages
|