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-Thread: 103376,75f02dbbddbbdc88 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.75.170 with SMTP id d10mr3369259pbw.6.1323908950160; Wed, 14 Dec 2011 16:29:10 -0800 (PST) Path: lh20ni23322pbb.0!nntp.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!217.73.144.44.MISMATCH!ecngs!feeder.ecngs.de!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 14 Dec 2011 18:29:09 -0600 User-Agent: NewsTap/3.5.1 (iPad) From: Martin Dowie Newsgroups: comp.lang.ada Mime-Version: 1.0 Message-ID: <778917968345601399.621922martin-re.mo.ve.thedowies.com@news.btinternet.com> Subject: Re: Pop function References: <27517259.83.1323907586856.JavaMail.geo-discussion-forums@yqgn9> Date: Wed, 14 Dec 2011 18:29:09 -0600 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-fLWI00Qup7SVxYWswtJZCtOa0aFG06xciqBI96Nq6fAUIvC75rDcaCNtOzfCWyn5wDqveTitb4BDFq2!yMIZCjm/OiLfD/hRCK0JRAhPIe3/VFrVu7dsHE1aTdMGMv64QrLgwekTh8QEY/C3rn8I6T32JU8J!5f7Sw4ImwDWEJWJgnR2HXcIWfNw7lRG3jsV5QaFh++hSmyjA X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2496 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Date: 2011-12-14T18:29:09-06:00 List-Id: "Rego, P." wrote: > Hello, > > Given a list type > type T_List is > record > Next : access T_List; > Item : Integer; > end record; > T_List_Ptr is access T_List; > > Is it right to implement a pop function like the following? (Free is an > Unchecked_Deallocation) > function Pop (Sender : access T_List) return Integer is > Current_Sender_Ptr : T_List_Ptr := T_List_Ptr (Sender); > Current_Item : constant T_List := Sender.Item; > begin > if Sender /= null then > if Sender.Next /= null then > Current_Sender_Ptr := T_List_Ptr (Current_Sender_Ptr.Next); > end if; > Free (Current_Sender_Ptr); > return Current_Item; > else > return 0; > end if; > end Pop; > > I mean, if I set Current_Sender_Ptr := T_List_Ptr > (Current_Sender_Ptr.Next), it's equivalent to Sender := Sender.Next? > (which I could not do directly due to in this case it would not be > allowed an anonymous reference, right?) If Sender is null, your in trouble before you get to "begin". Also, is it really ok to return 0 from an empty list rather than raising an exception? What does Sender "point to" on return if the head of the list is removed? -- Martin -- -- Sent from my iPad