sequence points in function args' expressions

David Lai lai at mips.COM
Thu Jan 18 19:15:20 AEST 1990


I have a question regarding the interpretation of the standard.  The 
following code fragment (simplified):

	f( (p=&a,*p), (p=&b, *p), (p=&c, *p));

is intended to be equivalent to:
	
	f(a, b, c);

where a, b, c, and *p are the same type (lets say int).

Does the standard specify if f(a,b,c) is the only interpretation.
Or perhaps f(c,c,c) is also legal.

I point to the standard, section 3.3.17 (Comma operator):
	"The left operand is evaluated as a void expression, there is
	 a sequence point after its evaluation.  Then the right operand
	 is evaluated..."
However this is seemingly contradicted by 3.3.2.2 (Function calls):
	"The order of evaluation of the function designator, the
	 arguments, and subexpressions within the arguments is
	 unspecified, but there is a sequence point before the call."

Is it legal execute all of the left hand side expressions first:
	p = &a
	p = &b
	p = &c

then perform the function call:
	f(*p, *p, *p);  /* this effectively is f(c,c,c) */

Is there anything in the standard which specifies that among several
comma expressions to be executed in unspecified order, that the order
of execution of an individual comma expression, the right side must
be evaluated immediately after the left hand side.  That is without
intervening evaluations of the left hand side of any other comma expression.

I have seen compilers which interpret the call as f(a,b,c); but also other
compilers interpret it as f(c,c,c).  Are there bugs with the compilers?
-- 
        "What is a DJ if he can't scratch?"  - Uncle Jamms Army
     David Lai (lai at mips.com || {ames,prls,pyramid,decwrl}!mips!lai)



More information about the Comp.std.c mailing list