Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!dkuug!freja.diku.dk!rimfaxe.diku.dk!null From: null@rimfaxe.diku.dk (Niels Ull Jacobsen) Newsgroups: comp.lang.c Subject: Re: C problem, order of evaluation Keywords: C, evaluationordrer, problem Message-ID: <1990Apr10.195822.14808@diku.dk> Date: 10 Apr 90 19:58:22 GMT References: <1990Apr8.185047.7385@diku.dk> <19539@grebyn.com> <16415@haddock.ima.isc.com> Sender: news@diku.dk (The Netnews System) Distribution: comp Organization: Department Of Computer Science, University Of Copenhagen Lines: 55 karl@haddock.ima.isc.com (Karl Heuer) writes: >In article <1990Apr8.185047.7385@diku.dk> null@diku.dk (Niels Ull Jacobsen) writes: >>I need to make an expression of the type: >> >>"( stack[++sp]= exp , stack[sp -= N])", where exp contains N "stack[++sp]"'s. >> >>The expression is supposed to have the value of the right side of the >>assignment, and to push this on the stack as well. The expression is to be a >>part of a function argument, and can therefore not contain any local block >>declarations. >I think the problem was with the multiple references to `sp' on the left side >of the comma. Niels: am I correct in assuming that > (stack[++sp] = stack[++sp] + stack[++sp], stack[sp -= 2]) >is an example of the generated code? >My recommendation is to force your translator to generate code like > (++sp, stack[sp] = stack[sp+1] + stack[sp+2]) >instead. That's the only way to be sure that the compiler knows what you're >talking about. Thank you, but your assumption is wrong. I am not making a stack machine, so the arguments will not be on the stack. The exp could itself contain expressions of this type. I could have an expression like : (stack[++sp] = g((stack[++sp] = make_cons(x,y), stack[sp -= 0]), (stack[++sp] = make_cons(x,z), stack[sp -= 0])), stack[sp -= 2]) The stack is actually only used to keep track of the cons-cells for the garbage collection. >Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint In article <19539@grebyn.com> ckp@grebyn.UUCP (Checkpoint Technologies) writes: >Well, then, you're using ++sp many times in the same expression it >seems, once on the left side ("stack[++sp] = ..." and several times on >the right. This is not gonna work. But I do have a suggestion. >I presume you're building a stack machine, such that a stack operator >takes several stack arguments, pops them, and writes one stack result >in their place. Try doing it this way: >( sp += N, stack[sp] = exp) >where exp contains several instances of stack[sp-C], > where each C is a negative offset to the argument you wish. Thank you, but that won't work either, see above. Niels Ull Jacobsen, Inst. of Datalogy, U of Copenhagen. null@diku.dk (Speaking from the void ..)