Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!adm!xadmx!Brantly.WBST129@xerox.com From: Brantly.WBST129@xerox.com Newsgroups: comp.lang.pascal Subject: Re: Funny evaluation of functions Message-ID: <20715@adm.BRL.MIL> Date: 28 Aug 89 11:57:09 GMT Sender: news@adm.BRL.MIL Lines: 44 Just to add on to Tom Wiencho's excellent response: Re: "This is, of course, the difference between passing values by reference (var) and passing them by value. You generally do not want to pass by reference if you plan on monkeying with the passed variables unless you want the side effects." RE: ">> >> The following code produces 25 as output in Turbo Pascal 4.0. Can >>anyone explain what is going on? >> >> var y:integer; >> >> Function one(var x:integer):integer; >> begin >> x:=x+1; >> one:=x; >> end; >> begin >> y:=4; >> writeln(output,y*one(y)); >> end. ------ On pg. 67 of the Turbo Pascal User's Guide (5.0) it is stated: "The keyword VAR in front of X and Y in GetData's procedure statement (as shown on pg 66) says that the actual paramenters must be variables and that the variable values can be changed and passed back to the caller." In other words by using VAR you're explicitly telling the compiler that it can do this [change the value of your variable]. This is NOT a weakness in the Turbo compiler, but built-in flexibility for use by the programmer [ and ya know how programmers are, give us enough rope and we'll create a bug! ] Dennis R&D -Team Xerox- Joseph C. Wilson Center for Technology Webster, NY