Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!uxc.cso.uiuc.edu!tank!eecae!netnews.upenn.edu!vax1.cc.lehigh.edu!vlsi3b15!lehi3b15!edkay From: edkay@lehi3b15.csee.Lehigh.EDU (Ed Kay) Newsgroups: comp.lang.pascal Subject: Re: Funny evaluation of functions Summary: What I thought was funny Message-ID: <616@lehi3b15.csee.Lehigh.EDU> Date: 28 Aug 89 21:38:31 GMT References: <20715@adm.BRL.MIL> Organization: CSEE Dept. Lehigh University, Bethlehem, PA Lines: 34 When I originally posed the question about the evaluation of X:=4; WRITELN(OUTPUT,X*ONE(X)); where FUNCTION ONE(VAR X:REAL):REAL; BEGIN X:=X+1; ONE:=X; END. I was mildly surprised that result was 25 rather than 20, because I thought that the evaluation of X might precede the evaluation of ONE(X). I should have more clearly stated that I was curious whether the STANDARD had anything to say about the issue. Some writers of private letters have stated that the STANDARD says that the order of evaluation is up to the implementor. I encountered the question in the context of wanting to write a procedure that had a side-effect on the variable X, and I was being cautious about when I accessed X. I wanted to be sure that I accessed X after it had been changed. I originally wrote WRITELN(OUTPUT,ONE(X)*X) to be sure that X was changed and then became curious whether my caution was warranted in Turbo 4.0. In practice, I would opt for the version in this paragraph, which in most (all?) compilers would yield the desired result. In any case, I left behind a large caution sign about the trickery I was indulging in. (Please note, that the actual code I wrote was not the example I originally posted, but the example catches the spirit of the actual code.) Edwin Kay CSEE Lehigh University