comp.lang.ada
 help / color / mirror / Atom feed
From: Pawel Kobylarz <kobylarz@wbkst21.mach.uni-karlsruhe.de>
Subject: Re: Unbounded array
Date: 1999/04/27
Date: 1999-04-27T00:00:00+00:00	[thread overview]
Message-ID: <37260F1E.17592342@wbkst21.mach.uni-karlsruhe.de> (raw)
In-Reply-To: 7g23a9$k3k$1@nnrp1.dejanews.com

Robert Dewar wrote:

> In article
> <37247AA2.116F5E00@wbkst21.mach.uni-karlsruhe.de>,
>   kobylarz@wbkst21.mach.uni-karlsruhe.de wrote:
> > Is there in ADA a way to obtain something like unbouned
> > array?
>
> Well most certainly you can use EXACTLY the same procedure
> you use in C (lookup allocators and the NEW keyword in your
> Ada text book).
>
> But if you are using GNAT, also look up GNAT.Table (in file
> g-table.ads) which provides exactly the abstraction you are
> looking for.
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own


The GNAT.table does not seem to work correctly, and there is also
something strange in the
definition.


Let's suppose I want to enlarge the table. Here are two definitions from
the
g-table.ads file:


   procedure Set_Last (New_Val : Table_Index_Type);
   pragma Inline (Set_Last);
   --  This procedure sets Last to the indicated value. If necessary the
   --  table is reallocated to accomodate the new value (i.e. on return
   --  the allocated table has an upper bound of at least Last). If
Set_Last
   --  reduces the size of the table, then logically entries are removed
   --  from the table. If Set_Last increases the size of the table, then
   --  new entries are logically added to the table.

   procedure Increment_Last;
   pragma Inline (Increment_Last);
   --  Adds 1 to Last (same as Set_Last (Last + 1).




The strange thing is that the functions does not take object as a
parameter.
They cannot be called like
                   table'Increment_Last;
            or
                   table.Increment_Last;
            or
                   Increment_Last(table);
there are compilation erros.

However, line like:
                          Increment_Last;
does compile!
The question is: if I have two object of that class and want to resize one
of them,
how should I call it?

I was also curious what is the effect of the function. I wrote


type My_Type is
  record
     ...
   end record;

subtype My_Idx_Type is Integer;

package t_mytype is new Gnat.Table(My_Type, My_Idx_Type, 1, 1, 10);
table : t_mytype.Table_Ptr;

begin
      loop
          Put_Line("before...");
          Increment_Last;
          Put_Line("after!");
     end loop
end;




and I obtained
        before...
        after!
        before...
and the program hanged in this place.

Seemingly the function does not work and I cannot even imagine, how can it
work without
taking object as a parameter.
Any suggestions?

Pawel Kobylarz






      parent reply	other threads:[~1999-04-27  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-04-26  0:00 Unbounded array Pawel Kobylarz
1999-04-26  0:00 ` Robert Dewar
1999-04-27  0:00   ` Pawel Kobylarz
1999-04-28  0:00     ` Matthew Heaney
1999-04-29  0:00     ` Matthew Heaney
1999-04-29  0:00       ` dennison
1999-04-27  0:00   ` Pawel Kobylarz [this message]
replies disabled

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