[comp.std.c] sequence points

grogers@convex.com (Geoffrey Rogers) (06/28/90)

In article <1988@mcrware.UUCP> jejones@mcrware.UUCP (James Jones) writes:
>Suppose one has an expression of the form
>
>	func1(<argument list>) + func2(<argument list>)
>
>Can a standard-conforming implementation evaluate *both* argument lists before
>calling either function?
>

The dp ANSI, Dec 89, page 42, states "The order of evaluation of the function
designator, the arguments, and subexpressions within the arguments are 
unspecified, but there is a sequence point before the actual call". This
would lead me to believe that you can evaluate all of the arguments for
both functions before calling either one. Most compilers I seen do evaluation
a function at a time.

+------------------------------------+---------------------------------+
| Geoffrey C. Rogers   		     | "Whose brain did you get?"      |
| grogers@convex.com                 | "Abbie Normal!"                 |
| {sun,uunet,uiucdcs}!convex!grogers |                                 |
+------------------------------------+---------------------------------+

gwyn@smoke.BRL.MIL (Doug Gwyn) (06/28/90)

In article <103459@convex.convex.com> grogers@convex.com (Geoffrey Rogers) writes:
>>	func1(<argument list>) + func2(<argument list>)
>The dp ANSI, Dec 89, page 42, states "The order of evaluation of the function
>designator, the arguments, and subexpressions within the arguments are 
>unspecified, but there is a sequence point before the actual call". This
>would lead me to believe that you can evaluate all of the arguments for
>both functions before calling either one.

The important point is that the + operator does not impose an order of
evaluation on its operands.  As you note, the arguments to a function
must be completely evaluated (including side effects) before the
function is called.  How much before is not specified, other than that
it must be after the previous sequence point.

diamond@tkou02.enet.dec.com (diamond@tkovoa) (06/29/90)

In article <1988@mcrware.UUCP> jejones@mcrware.UUCP (James Jones) writes:
>>Suppose one has an expression of the form
>>	func1(<argument list>) + func2(<argument list>)
>>Can a standard-conforming implementation evaluate *both* argument lists before
>>calling either function?

In article <103459@convex.convex.com> grogers@convex.com (Geoffrey Rogers) writes:
>The dp ANSI, Dec 89, page 42, states "The order of evaluation of the function
>designator, the arguments, and subexpressions within the arguments are 
>unspecified, but there is a sequence point before the actual call".

This is 100% true.

But there are lots of other places where sequence points can occur too.
Suppose an argument contains an imbedded comma operator.  That means that
certain other operations must have been completed before this sequence
point.  What kinds of other operations must have been completed?  Other
function calls?

Is there a sequence point after the return from the actual call?  I would
guess not, by default, since the standard does not say.  Would the committee
have put one there if they had thought of this problem?  Maybe the
interpretation committee will decide that that it is just an editorial matter
and tell us that the standard does say something about it?

>This would lead me to believe that you can evaluate all of the arguments for
>both functions before calling either one.

I agree with this conclusion too, but feel uncomfortable with it.

>Most compilers I seen do evaluation a function at a time.
(Except of course for common subexpression elimination.)
-- 
Norman Diamond, Nihon DEC     diamond@tkou02.enet.dec.com
This is me speaking.  If you want to hear the company speak, you need DECtalk.

gwyn@smoke.BRL.MIL (Doug Gwyn) (06/29/90)

In article <1822@tkou02.enet.dec.com> diamond@tkou02.enet.dec.com (diamond@tkovoa) writes:
>Is there a sequence point after the return from the actual call?  I would
>guess not, by default, since the standard does not say.  Would the committee
>have put one there if they had thought of this problem?  Maybe the
>interpretation committee will decide that that it is just an editorial matter
>and tell us that the standard does say something about it?

First tell us what "the problem" is supposed to be.  The only issue
regarding this that I am aware of that is not 100% clear concerns
whether the license granted for assignment can creep into the body
of a function used in the RHS.  There is a request for interpretation
still pending on this.  If you see some other problem, submit a
request for interpretation.

scott@Apple.COM (scott douglass) (06/30/90)

In article <1988@mcrware.UUCP> jejones@mcrware.UUCP (James Jones) writes:
>Suppose one has an expression of the form
>
>	func1(<argument list>) + func2(<argument list>)
>
>Now, there are two sequence points here, namely those occurring after the
>evaluation of the argument list of each of the functions and before the
>call.  On the other hand, one can't count on which of the two functions will
>be called first.

A closely related question* that has been bothering me for a couple
months is:
    Do func1 and func2 have to be executed atomically (that
    is, one completely before the other but only the compiler
    knows which) or can they be executed in parallel?

Stating this question a different way:
    Where in the standard does it say that the next sequence point
    will be in the same function as the previous one?  (Assuming that
    there is another sequence point in this function.)

In fact:
    Where in the standard does it say which is the next sequence point
    after the one just before a function call?  Can you prove that any
    of the sequence points in the called function will, in fact, be
    reached?

In general, the standard seems to leave the question of "Which is the
next sequence point?" undefined so there is only a partial ordering on
sequence points.  One of the most restrictive quotes is this somewhat
vauge one in section 3.6 Statements:
    "Except as indicated, statements are executed in sequence."

I'm working from a Dec 88 draft.

Obviously, to me anyway, you do want a guarentee that called functions
will be (as if) executed.  Also it seems likely to break quite a bit
of existing code if the two functions may be run in parallel.

Thanks for your help.

	--scott douglass (scott@apple.com)

p.s.  If the answer to this is "send it to the committe for interpret-
ation", please give me explicit instructions on how to do it.

(*) This actually arose from a difference of opinion I have with CFront
about it's implementation of inlining.  I botched a posting to
comp.lang.c++ trying to get an answer to my question in it's original
form.  Since the C++ answer depends on the answer to this question
I'm trying again here.  I've also read P.J. Plaugher's article "Sequence
Points and Parallelism" in The Journal of C Language Translation but
unfortunately it didn't address this question.  I've even asked Bjarne
and he didn't give me an answer.  You people are my only hope.
-- 
	--scott douglass	scott@apple.com