From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9eef6c480abeecf8 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 11 Feb 2005 07:43:01 -0600 Date: Fri, 11 Feb 2005 08:43:20 -0500 From: Jeff C User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Dynamic array allocation and STL equivalents? References: <1108127216.221977.60830@o13g2000cwo.googlegroups.com> In-Reply-To: <1108127216.221977.60830@o13g2000cwo.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <-vSdnXx93NX4K5HfRVn-2Q@comcast.com> NNTP-Posting-Host: 24.147.74.171 X-Trace: sv3-ZYeXxTzU2Q4z/GPt9UCLtfVP5ZQ3xKAezjxKOVBXCLCQs/+FlsrkDqNzfjfF6AAr/CnoGe6QX2ROm3A!mPuGvU3E8Up5a1gwXeDpe/Wd5htpihl5TRUd5IKorTtZS3m3JpKHekR4YUfJCQ== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.23 Xref: g2news1.google.com comp.lang.ada:8239 Date: 2005-02-11T08:43:20-05:00 List-Id: brian.b.mcguinness@lmco.com wrote: > > Recently, while looking through a list of GNU software, I was reminded > that there is a Gnu Ada compiler, so I installed it on a computer at > home, along with its library. So far I have not found an rpm package > of GtkAda for Fedora Core 3, but I am still looking. > You probably won't find it. I know people can be adverse to installing things via non-rpm means but there are times when you don't have an obvious choice. What I have done is to setup something like /opt/localmanaged as a root for packages like this. Futher, I use Checkinstall http://asic-linux.com.mx/~izto/checkinstall/ to do the install/create the RPM. It is not a perfect approach but it generally works. I have not done this exact matching (GtkAda and Fedora Core 3) using this method (because sometimes I get lazy and just do an install into my home directory if I am doing some short term testing). > I would like to write a few Ada programs and play around with the > language a bit. From the mid 1980s through the early 1990s I wrote > programs in Borland Turbo Pascal 3 through 6, which I was quite fond > of, so I shouldn't have much trouble picking up Ada, which has a > similar syntax. But there are a few things I don't know how to do. > For one thing, I have looked through the Barnes book, the pages of > which have turned tan with age, and online, but can't find any > information on how to allocate arrays dynamically; there seems to be no > equivalent to the C malloc() function or the C++ dimensioned new. If > someone would tell me how to do this, I would appreciate it. > -- -- WARNING - NOT TESTED/NOT COMPILED SEMI-PSEUDO CODE TO ILLUSTRATE -- POINT. -- with Unchecked_Deallocation; type My_Array is (integer range <>) of Float; type Access_My_Array is access My_Array; procedure Free is new Unchecked_Deallocation(My_Array, Access_My_Array); A : Access_My_Array; begin A := new My_Array(10 .. 1000); -- Made up bound, can be fully dynamic Free(A); -- Return storage....Since I figured that was the next question end; Note that you can more often than not avoid using access types (pointers) in Ada but clearly they still have lots of important uses. > It would also be useful to know if there is an Ada equivalent of the > C++ Standard Template Library, with classes for vectors, associative > arrays, and so on. > Ada is at a transition point with respect to this. Previously the standard libraries that shiped with Ada compilers did not include anything exactly like (or certainly as encompassing) as the STL. The new Ada Standard (I think we are still calling it Ada 0Y) where Y may be = 5. Does include a larger set of predefined packages Some of these packages have essentially been backported to operate with an Ada 95 compiler http://www.martin.dowie.btinternet.co.uk/ There are also several others available (like the widely discussed Booch Components). Take a look at http://www.adapower.com/index.php?Command=Class&ClassID=AdaLibs&Title=Ada+Libraries (in fact, poke around the entire www.adapower.com site and www.adaworld.com sites for other good info) > One interesting project would be to create an object class hierarchy to > implement APL arrays. In APL, the lengths of an array's dimensions can > change, e.g. by concatenating new rows or columns onto a matrix, or > concatenating two matrices, and the number of dimensions can also > change, e.g. by "laminating" two 12x30 arrays to form a 2x12x30 array. > In C++, an obvious solution would be to use STL vectors, e.g.: > > class RealArray { > private: > vector dimensions; > vector data; > public: > // define an indexing operator[] to use the dimensions > // vector to translate sets of indices into offsets > // into the data array > ... > }; > > But I don't know how to do this in Ada. This might be pretty fun. One thing that would have to be different is that Ada 95 does not allow one to overload the array index "operator" (). Perhaps you should have a look at the Ada 95 for C++ tutorial at the (essentially dead) website http://www.adahome.com/Ammo/cpp2ada.html (Don't be fooled by the date on the front page of this website that updates every day...The site went static about 5 years ago..Still has some good old reference info)