More Re: Function Argument Evaluation argument

Blair P. Houghton bhoughto at bishop.intel.com
Thu Apr 11 10:45:30 AEST 1991


In article <1991Apr10.191853.4604 at cs.ucla.edu> jon at maui.cs.ucla.edu (Jonathan Gingerich) writes:
>In article <3731 at inews.intel.com> bhoughto at nevin.intel.com (Blair P. Houghton) writes:
>>In article <1991Apr8.191009.24897 at cs.ucla.edu> jon at maui.cs.ucla.edu (Jonathan Gingerich) writes:
>>>Earlier I claimed:
>>>	printf("%d %d\n", f(...v...), f(...v++...))
>>[was unspecified not undefined]
>>
>>However, the first usage of `v' has no side effects.
>>It can be evaluated regardless of sequence points
>>other than the one for the leftward call to f().
>>The value for `v' in the leftward call is indeterminate.
>
>You are correct as far as you go.  But v and v++ can both be evaluated before
>either s.p. associated with the application of f()'s and because v is both
>read and written in separate actions it's undefined.

Okay, make them both v++.  Now it's definite that the
sequence must be:

	v++, corresponding s.p., v++, corresponding s.p.

though which v++ and corresponding s.p. come first is
still unspecified.

Doug (or was it Guy?) once made the point about parsing of
tokens that maximal munch doesn't hold, rather it is the
parsing that is true to the syntax that holds.  I think
that here a similar situation exists.  It's possible to
create only two orderings of the evaluations and sequence
points in

	f( g(v), h(v++) )

SUCH THAT the statement is NOT "undefined", and they are

	v, s.p.(g), v++, s.p.(h)
	v++, s.p.(h), v, s.p.(g)

and the compiler should produce one of these orderings.

I.e., if it's possible to avoid undefined behavior by
application of sequence points that are defined to
exist, then they should be so applied.

(Note that the side effects don't force placement
of the sequence points, here.  The same thing would
happen if `v++' were replaced by `v' in both arguments.)

I believe that this is what the standard mandates; but it
may be the opposite:  that if there is ANY way to produce
undefined behavior by pushing around the unanchored
sequence points, then the behavior should be undefined.

				--Blair
				  "But then, I go through red
				   lights at 3 a.m. if there's
				   no cross-traffic, too..."



More information about the Comp.std.c mailing list