Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!bbn!rochester!PT.CS.CMU.EDU!IUS1.CS.CMU.EDU!edw From: edw@IUS1.CS.CMU.EDU (Eddie Wyatt) Newsgroups: comp.unix.questions Subject: Re: Wierd Compilers Message-ID: <318@PT.CS.CMU.EDU> Date: Fri, 6-Nov-87 17:33:48 EST Article-I.D.: PT.318 Posted: Fri Nov 6 17:33:48 1987 Date-Received: Sun, 8-Nov-87 21:50:52 EST References: <367@white.gcm> <18964@amdcad.AMD.COM> <44177@beno.seismo.CSS.GOV> <1182@tut.cis.ohio-state.edu> Sender: netnews@PT.CS.CMU.EDU Organization: Carnegie-Mellon University, CS/RI Lines: 49 > > Forgive a possibly stupid question, but in what way is there any > difference between a++ and ++a in the generated code, even with the > optimiser disabled. > > Note: I am not arguing with you, merely asking for more information. > > In case 1 (a++) the value store in "a" may have to be saved before executing the increment if the value of the expression is used. In case case 2 (++a) the value stored in "a" after the operation is preformed. Hence no extra save must be preformed. Example: case 1 i = a++; save a in b increment a i gets b case 2 i = ++a; increment a i gets a; Note there is an optimization that can be made for the first case that is : i get a increment a But this optimization assumes that the order of the evaluation ++ and assignment don't matter (however in some cases it does). a = 1; a = a++; The unoptimized case would yields an "a" value of 1. The optimized case would yield an "a" value of 2. This really shows that there is an ambiguity in the language definition. They should have used denotational semantics. -- That one looks Jewish -- And that one's a coon -- Who let all this riff raff into the room -- There's one smoking a joint -- and Anoter with spots -- If I had my way -- I'd have all of you shot ... Pink Floyd, "In the Flesh" Eddie Wyatt e-mail: edw@ius1.cs.cmu.edu