Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!news.cs.indiana.edu!news.nd.edu!mentor.cc.purdue.edu!purdue!haven!adm!news From: CDCKAB%EMUVM1.BITNET@cunyvm.cuny.edu ( Karl Brendel) Newsgroups: comp.lang.pascal Subject: Re:Turbo bug with VAR parameters Message-ID: <25791@adm.brl.mil> Date: 1 Feb 91 14:35:58 GMT Sender: news@adm.brl.mil Lines: 64 In article 683@saxony.pa.reuter.COM, (Dave Gillett) wrote: > Consider the following trivial example: > >var > Global : String [255]; > > procedure Foo (VAR FooStr : String [255]); > > begin > FooStr := 'abcdefghijklmnopqrstuvwxyz'; > end { Foo }; > > procedure Bar (VAR BarStr : String [255]); > > begin > Foo (BarStr); > end { Bar }; > >begin > Bar (Global); >end. > > When I compile this using version 5.5 of Turbo Pascal (okay, >this might be fixed in 6.0 for all I know), Foo gets compiled to >access FooStr by reference rather than by value; apparently, as a >pointer back into the previous stack frame. Similarly, Bar gets >compiled to generate such access for BarStr. > The problem is that, at run-time, Foo trashes Bar's stack >frame, instead of reaching all the way back to the global context to >resolve FooStr -> Global. > [...remainder deleted...] Are you sure you're seeing what you think you are? I modified your example code sufficiently to allow it to compile (under 5.5). (TPas didn't like your declaration of VAR parameters as "String [255]".) I used these compiler switches for testing: In TPC.CFG: /$V- /$O+ In the program proper: {$L+,D+,S-,R-} Loading the program under TD 2.01, I examined the resulting code in a CPU window, and traced through its execution several times. It was very apparent that both the program code and system library code properly passed the address of Global to the code which did the actual assignment. No stack problems of any kind were apparent. Try this yourself _with your example_. If you can recreate the problem _with the example_, please email me. If not, please create a similarly small example which _does_ demonstrate the problem and repost. Cheers-- +--------------------------------------------------------------------+ | Karl Brendel Centers for Disease Control | | Internet: CDCKAB@EMUVM1.BITNET Epidemiology Program Office | | Bitnet: CDCKAB@EMUVM1 Atlanta, GA, USA | | Home of Epi Info 5.0 | +--------------------------------------------------------------------+