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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9e02dc5f2c4718ab,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-11-17 22:40:25 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn14feed!wn12feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc01.POSTED!not-for-mail From: Stapler Subject: Novice help with types and de-allocation. Newsgroups: comp.lang.ada User-Agent: Pan/0.11.3 (Unix) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Comment-To: ALL Message-ID: NNTP-Posting-Host: 12.241.145.39 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc01 1037601624 12.241.145.39 (Mon, 18 Nov 2002 06:40:24 GMT) NNTP-Posting-Date: Mon, 18 Nov 2002 06:40:24 GMT Organization: AT&T Broadband Date: Mon, 18 Nov 2002 06:40:24 GMT Xref: archiver1.google.com comp.lang.ada:31022 Date: 2002-11-18T06:40:24+00:00 List-Id: Alright, I have a package which more or less works but I'm having trouble in a couple spots. I've placed comments where I'm having trouble. with Ada.Unchecked_Deallocation; generic Size : Positive; package int_buff is type Int_Buffer is limited private; type Buff_Ptr is limited private; type Buff_Out is array(Positive range <>) of Integer; procedure Insert( X : in Integer; Y : in out Int_Buffer); procedure Clear_Buff( Y : in out Int_Buffer; Z : in out Buff_Ptr); procedure Ditch_Buff( Y : in out Int_Buffer; Z : in out Buff_Ptr); function Read_Buff( Y : in Int_Buffer; Read_length : in Natural; Loc :in Natural) return Buff_Out; function Sum_Buff( Y : in Int_Buffer) return Integer; private Buff_Indexer : Positive range 1..Size; type Int_Buffer is array(1..Size) of Integer; pragma Pack( Int_Buffer ); type Buff_Ptr is access Int_Buffer; procedure Free_Buff is new Ada.Unchecked_Deallocation(Int_Buffer, Buff_Ptr); end int_buff; package body int_buff is procedure Insert(X : in Integer; Y : in out Int_Buffer) is begin Buff_Indexer := X; Y(Buff_Indexer) := X; end Insert; procedure Clear_Buff( Y : in out Int_Buffer; Z : in out Buff_Ptr) is X : Int_Buffer; -- This procedure obviously needs more work. -- It's suppose to de-allocate the old buffer and create a new one. begin Free_Buff(Z); Y := X; end Clear_Buff; function Read_Buff(Y : in Int_Buffer; Read_Length : in Natural; Loc : in Natural) return Buff_Out is Ret_Buff : Buff_Out(1..Read_Length); begin -- For some reason, the compiler expects Y to be of type Buff_Out. -- Do I need to use Unchecked_Conversion here? Ret_Buff := Y(Loc .. Read_Length - 1); return Ret_Buff; end Read_Buff; function Sum_Buff( Y : in Int_Buffer) return Integer is Sum : Integer := 0; begin for I in Y'range loop Sum := Sum + Y(I); end loop; return Sum; end Sum_Buff; procedure Ditch_Buff(Y : in out Int_Buffer; Z : in out Buff_Ptr) is begin Free_Buff(Z); end Ditch_Buff; end int_buff; Try not to laugh to hard. I'm still a newb. Any pointers would be appreciated. Stapler "Still tilting at WindMills."