Article View: net.lang.c
Article #9203Re: Indirect comma assigned from side effects
From: Tainter
Date: Mon, 25 Aug 1986 20:57
Date: Mon, 25 Aug 1986 20:57
33 lines
1841 bytes
1841 bytes
> In article <3047@umcp-cs.UUCP>, chris@umcp-cs.UUCP (Chris Torek) writes:
> > In article <792@navajo.STANFORD.EDU> I write:
> > > int lhs, rhs, index; int *pointers[9];
> > > foo() { *( index=lhs, pointers[index] ) = sideeffects(); }
> > >The question is, does C allow for the possibility that the order
> > >of evaluation might be "index=lhs" then "sideeffects()" then
> > >"*pointers[index]=<result>"?
> > No. The compiler can, however, effectively generate either of the
> > following:
> Can someone second this, or show me the appropriate reference?
> It's Microsoft 4.0 that's putting the sideeffects() call between
> the two parts of the comma expression, and sideeffects() modifies
> index . . . you get the idea. I could find nothing in K&R, but
> I'm only been hacking C for a year or so.
>
> I just tested under 4.3bsd; cc also puts the sideeffects() in the
> middle. Comments, anyone?
>
> Thanks! -tom
As far as I can tell the only restriction on order of evaluation is
index=lhs before pointers[index].
Lets meta a bit:
*(a,b)= c;
can be evaluated:
c a b
a c b
a b c
If c plays with something also played with in a or b then you are in the
same boat as the people counting on order of evaluation in:
*a++ = *a + gunga_din;
--j.a.tainter
Technical Details
Message-ID:
<2401@ihlpg.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!caip!clyde!cbatt!cbosgd!ihnp4!ihlpg!tainterReferences:
<792@navajo.STANFORD.EDU> <3047@umcp-cs.UUCP> <796@navajo.STANFORD.EDU>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!caip!clyde!cbatt!cbosgd!ihnp4!ihlpg!tainter From: tainter@ihlpg.UUCP (Tainter) Newsgroups: net.lang.c Subject: Re: Indirect comma assigned from side effects Message-ID: <2401@ihlpg.UUCP> Date: Mon, 25-Aug-86 16:57:28 EDT Article-I.D.: ihlpg.2401 Posted: Mon Aug 25 16:57:28 1986 Date-Received: Tue, 26-Aug-86 18:48:19 EDT References: <792@navajo.STANFORD.EDU> <3047@umcp-cs.UUCP> <796@navajo.STANFORD.EDU> Organization: AT&T Bell Laboratories Lines: 33