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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9e02dc5f2c4718ab X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-11-18 11:06:31 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!nntp-relay.ihug.net!ihug.co.nz!west.cox.net!cox.net!newsfeed1.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3DD93A2B.70902@acm.org> From: Jeffrey Carter User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Novice help with types and de-allocation. References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 18 Nov 2002 19:06:31 GMT NNTP-Posting-Host: 63.184.9.177 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 1037646391 63.184.9.177 (Mon, 18 Nov 2002 11:06:31 PST) NNTP-Posting-Date: Mon, 18 Nov 2002 11:06:31 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:31064 Date: 2002-11-18T19:06:31+00:00 List-Id: Stapler wrote: > with Ada.Unchecked_Deallocation; > generic > Size : Positive; > > package int_buff is ... > 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); Why is Free_Buff here rather than in the body? > > 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; This is clearly not going to do anything useful. > > 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; There is no relationship between Y and Z. > > 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; Ret_Buff has type Buff_Out and Y has type Int_Buffer. You can only assign a value of type Buff_Out to a variable of type Out_Buff. What happens if Loc or Read_Length are not in the range of Y? > > 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; You may be referencing uninitialized components of Y. > > procedure Ditch_Buff(Y : in out Int_Buffer; Z : in out Buff_Ptr) is > > begin > > Free_Buff(Z); > > end Ditch_Buff; Why must the user supply Y? > > end int_buff; > > > Try not to laugh to hard. I'm still a newb. Any pointers would be > appreciated. There's no need for access types in what you're doing here. So instead of "any pointers" I would recommend "no pointers". -- Jeff Carter "When danger reared its ugly head, he bravely turned his tail and fled." Monty Python and the Holy Grail