comp.lang.ada
 help / color / mirror / Atom feed
From: Jeff C <jcreem@yahoo.com>
Subject: Re: Dynamic array allocation and STL equivalents?
Date: Fri, 11 Feb 2005 08:43:20 -0500
Date: 2005-02-11T08:43:20-05:00	[thread overview]
Message-ID: <-vSdnXx93NX4K5HfRVn-2Q@comcast.com> (raw)
In-Reply-To: <1108127216.221977.60830@o13g2000cwo.googlegroups.com>

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 <unsigned long> dimensions;
>     vector <double>        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)






  reply	other threads:[~2005-02-11 13:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-11 13:06 Dynamic array allocation and STL equivalents? brian.b.mcguinness
2005-02-11 13:43 ` Jeff C [this message]
2005-02-14 15:23   ` Marc A. Criley
2005-02-11 14:41 ` Dmitry A. Kazakov
2005-02-11 15:50   ` Adrien Plisson
2005-02-11 17:47   ` REH
2005-02-12  9:28     ` Dmitry A. Kazakov
2005-02-12 18:52       ` Robert A Duff
2005-02-11 17:24 ` Bobby D. Bryant
2005-02-12  0:06   ` Robert A Duff
2005-02-12  3:45     ` Bobby D. Bryant
2005-02-11 18:07 ` Matthew Heaney
2005-02-11 18:36   ` Martin Krischik
2005-02-11 19:35 ` brian.b.mcguinness
2005-02-12  1:04 ` Jeffrey Carter
2005-02-12  6:19 ` Bobby D. Bryant
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox