Article View: comp.std.c
Article #2640Re: More Re: Function Argument Evaluation argument
From: Christopher R Volpe
Date: Fri, 29 Mar 1991 13:19
Date: Fri, 29 Mar 1991 13:19
53 lines
2583 bytes
2583 bytes
In article <3547@inews.intel.com>, bhoughto@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@crd.ge.com
Technical Details
Message-ID:
<18021@crdgw1.crd.ge.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!camelback!volpeReferences:
<17936@crdgw1.crd.ge.com> <15607@smoke.brl.mil> <17983@crdgw1.crd.ge.com> <3547@inews.intel.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!camelback!volpe From: volpe@camelback.crd.ge.com (Christopher R Volpe) Newsgroups: comp.std.c Subject: Re: More Re: Function Argument Evaluation argument Message-ID: <18021@crdgw1.crd.ge.com> Date: 29 Mar 91 13:19:55 GMT References: <17936@crdgw1.crd.ge.com> <15607@smoke.brl.mil> <17983@crdgw1.crd.ge.com> <3547@inews.intel.com> Sender: news@crdgw1.crd.ge.com Reply-To: volpe@camelback.crd.ge.com (Christopher R Volpe) Lines: 53