comp.lang.ada
 help / color / mirror / Atom feed
* Re: Passing out unconstrained arrays??
       [not found] ` <6nghkl$ch3$1@nnrp1.dejanews.com>
@ 1998-07-02  0:00   ` Adam Beneschan
  0 siblings, 0 replies; only message in thread
From: Adam Beneschan @ 1998-07-02  0:00 UTC (permalink / raw)



In article <6nghkl$ch3$1@nnrp1.dejanews.com> dennison@telepath.com writes:
> 
>    Max_Returned_Items : constant := 5_000;
>    -- Bump this up if you get a Too_Many_Items exception
>
>    type Item_List is array (Natural range <>) of Integer
> 
>    subtype Returned_Item_List is Item_List (1..Max_Returned_Items);

Is there any reason not to just make the upper bound Integer'Last?
You're not actually allocating anything of this subtype, and you're
not going to access any array components beyond Num_Items anyway.
 
>    type Item_List_Ptr is access Returned_Item_List;
> 
>    type Integer_Ptr is access Integer;
> 
>    procedure C_Get_Data (Num_Data_Items : in System.Address;
>                          Data_Items     : in System.Address);
>    pragma Import (C, "get_data", C_Get_Data);
>    procedure C_Dealloc (Location : in Item_List_Ptr);
>    pragma Import (C, "dealloc", C_Dealloc);
> 
>    function Get_Data return Item_List is
>      Num_Items     : Integer;
>      Data_Returned : Item_List_Ptr;
>      Data : Returned_Item_List;
>    begin
>      C_Get_Data (Num_Items'address, Data_Returned'address);
> 
>      -- Do error handling
>      if Num_Items.all = 0 then
>        -- return a null array
>        return (2..1 => 0);
>      elsif Num_Items.all > Max_Returned_Items then
>        -- Wow. We need to raise the limit.
>        raise Too_Many_Items;
>      end if;
> 
>      Data(1..Num_Items.all) := Data_Returned.all(1..Num_Items.all);
>      C_Dealloc(Data_Returned);
>      return Data(1..Num_Items.all);
> 
>    end Get_Data;
> 
>    T.E.D.

                                -- Adam




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1998-07-02  0:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <6ne0gl$631$1@news.bctel.net>
     [not found] ` <6nghkl$ch3$1@nnrp1.dejanews.com>
1998-07-02  0:00   ` Passing out unconstrained arrays?? Adam Beneschan

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