Article View: comp.std.c
Article #1088sequence points in function args' expressions
From: David Lai
Date: Thu, 18 Jan 1990 08:15
Date: Thu, 18 Jan 1990 08:15
42 lines
1975 bytes
1975 bytes
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@mips.com || {ames,prls,pyramid,decwrl}!mips!lai)
Technical Details
Message-ID:
<34795@mips.mips.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!ames!vsi1!wyse!mips!gumby!laiShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!ames!vsi1!wyse!mips!gumby!lai From: lai@mips.COM (David Lai) Newsgroups: comp.std.c Subject: sequence points in function args' expressions Message-ID: <34795@mips.mips.COM> Date: 18 Jan 90 08:15:20 GMT Sender: news@mips.COM Lines: 42