Indirect comma assigned from side effects
Tainter
tainter at ihlpg.UUCP
Tue Aug 26 06:57:28 AEST 1986
> In article <3047 at umcp-cs.UUCP>, chris at umcp-cs.UUCP (Chris Torek) writes:
> > In article <792 at 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
More information about the Comp.lang.c
mailing list