Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!ccu.umanitoba.ca!herald.usask.ca!alberta!ubc-cs!van-bc!zaphod.mps.ohio-state.edu!wuarchive!ukma!usenet.ins.cwru.edu!ysub!psuvm!blekul11!ghgaqz4 From: GHGAQZ4@cc1.kuleuven.ac.be Newsgroups: comp.sys.amiga.programmer Subject: Re: Compiler code (was a flame fest) (now a lesser flame fest) Message-ID: <91113.092907GHGAQZ4@cc1.kuleuven.ac.be> Date: 23 Apr 91 09:27:07 GMT References: <1991Apr18.212939.3461@kessner.denver.co.us> <1991Apr19.032052.26387@engin.umich.edu> <91112.093750GHGAQZ4@cc1.kuleuven.ac.be> <1991Apr23.020319.7216@engin.umich.edu> Organization: K.U.Leuven - Academic Computing Center Lines: 46 >> >>I think you are wrong. Look at the following results : >>I have tried this with our mainframe compiler : >> int n=4; >> >> (n--)*(n++) -> 12 >> (n++)*(n--) -> 20 >> (--n)*(++n) -> 16 >> (++n)*(--n) -> 16 >> (--n)*(n++) -> 12 >> (++n)*(n--) -> 20 >> (n--)*(++n) -> 16 >> (n++)*(--n) -> 16 >> >> Jorrit Tyberghein > > You missed my point. I was saying that ++ and -- are unary operators which >will be evaluated before the multiplication. You've pointed out the argument >this stems from, which is that there's no way to know which side of the mult- >iplication is evaluated (You're compiler does the left first..). There is something I don't understand about this. You say that the compiler evaluates left first. But how do you interprete (--n)*(++n) ? If the compiler would go from left to right he should first compute --n (or n=n-1). This is the left side of the expression. And after that the compiler would evaluate (++n) which is the right side of the expression. Obviously I'm thinking wrong because this would give 12 instead of 16. What really happens here is that (--n)*(++n) gets translated to : --n ++n (n)*(n) (or something equivalent) I've looked at the compiled code and this is indeed what is evaluated. But why does (n++)*(n--) not evaluate to the equivalent : (n)*(n) n++ n-- I thought that ALL --x or ++x operators where to be evaluated BEFORE the evaluation of the total expression happens (and this is presumably also what happens) and that ALL x++ or x-- operators where to be evaluated AFTER the evaluation of the total expression (and this is presumably not true). This would seem more logical to me. By the way. Lattice C generates exactly the same results. Jorrit Tyberghein