Newsgroups: comp.lang.pascal Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!zaphod.mps.ohio-state.edu!sdd.hp.com!decwrl!elroy.jpl.nasa.gov!zardoz.cpd.com!dhw68k!silk From: silk@dhw68k.cts.com (Mitch Gorman) Subject: Re: Dynamic arrays in TP5.0 Message-ID: <1990Jul13.062641.13434@dhw68k.cts.com> Reply-To: silk@dhw68k.cts.com (Mitch Gorman) Organization: Wolfskill & Dowling residence; Anaheim, CA (USA) References: <1831@krafla.rhi.hi.is> <1990Jul8.200026.29195@mthvax.cs.miami.edu> Date: Fri, 13 Jul 90 06:26:41 GMT In article <1990Jul8.200026.29195@mthvax.cs.miami.edu> mathrich@mthvax.cs.miami.edu (Rich Winkel) writes: >In <1831@krafla.rhi.hi.is> binni@rhi.hi.is (Brynjolfur Thorsson) writes: >>I am trying to use dynamic arrays in my TP5.0 program but am having a hard >>time. I want to be able to do things like they are done in C, e.g. > >>*(x + 10) = 100.5 > >>but I have not found a way to do it. Below is a short program demonstrating >>what I want to do, but I have no idea, how to make GetVal and PutVal. If you >>have suggestions for me I would appreciate it. I can't believe that this is >>impossible in TP. > >>*************************************************** >>Program dynamic; > >>Var >> y : ^array [1..10] of Real; <---- >> x : Real; > >>Begin >> GetMem(y, SizeOf(^y)); <---- >> ^y[5]:=12.34; <---- >> x :=^y[3]; <---- >>End. > >I believe this will work. > >Rich Yes, this method will work, but it misses the point of what Brynjolfur wants to do. Of course, there's nothing wrong with this method, but it seems to me that the idea is to explicitly declare an array normally, not declare a pointer to an array. Those functions (Putval and Getval) could be made to work inelegantly by simply passing the address of the array (which happens automagically, of course), and the size of the data elements which constitute the array. This way, details of how to get to the desired element are hidden (gotta love this abstraction crap! :^), and it has the advantage of not requiring a special declaration for the array you plan to access by this method (viz *(array + n)). Those functions would simply add the multiple of the index into the array and the size of the elements to the base address of the array. It's not even necessary to force the issue by passing "&array", since that can be done inside the routines (again, for transparency). Of course, the truth is that I'm babbling off the top of my head, and haven't tested this garbage I'm spouting, so perhaps it's time for me to shut up now. :^) _______________________________________________________________________________ Mitch Gorman Internet: silk@dhw68k.cts.com uucp: ...{spsd,zardoz,felix}!dhw68k!silk ------------------------------------------------------------------------------- "Never seen the same face twice, never walked the same way; And the little love that I have known I keep to myself." - Genesis, "Say It's Alright, Joe", _And Then There Were Three_ _______________________________________________________________________________