More Re: Function Argument Evaluation argument
Christopher R Volpe
volpe at camelback.crd.ge.com
Fri Mar 29 23:19:55 AEST 1991
In article <3547 at inews.intel.com>, bhoughto at pima.intel.com (Blair P.
Houghton) writes:
|>Insert a sequence-point:
|>
|> char *x = "foo", *y = "bar";
|>
|> printf("\t%s %s\n", (p = x)?p:"(nil)", (p = y) );
|>
|>Now the behavior is defined, since there's a sequence point
|>after the first assignment to p, but no way to tell
|>which of the p's is returned after either question mark.
I don't think that's necessarily true. The order of evaluation of
arguments to the function call is unspecified, so it could evaluate
(p=y) first and then (p=x)?p:"(nil)", with no sequence point between
the two assignments. It's true that there's a sequence point after
the evaluateion of (p=x) and before the evaluation of either p or "(nil)",
but I don't think that's sufficient.
|>
|>Depending on the order in which the placing of the first
|>argument on the stack and the assignment of y to p are
|>performed. It seems to me, though, that since I asked
|>for "p" and not "the result of p only due to the first
You asked for the value of p immediately following the sequence point
that follows the evaluation of (p=x).
|>argument", then the value should have to wait for the
|>side-effects (the actual storage is a side-effect
|>of assignment (sec. 3.3.16, p. 54, ll. 14-16)) of
|>other argument-expressions before it is placed on the
|>stack.
|>
|>I didn't need the obfuscation of the `?:', either.
|>
|> f(p,p=y);
Section 3.3: "Furthermore, the prior value [of an object] shall be accessed
only to determine the value to be stored." Between sequence points,
you are modifying p, and referencing p in a way that is not used to determine
the new value of p (i.e. the first argument to f). The behavior of
your example is undefined.
|> --Blair
|> "[6] I get it. '2001: A Space Odyssey'
|> is all about the perils of nonconformance.
|> :-) :-) Kubrick, what a visionary!"
==================
Chris Volpe
G.E. Corporate R&D
volpecr at crd.ge.com
More information about the Comp.std.c
mailing list