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,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,20df27b13b7ee81e,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-12-17 19:35:51 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: bilbo@volcanomail.com (Antoine Lec.) Newsgroups: comp.lang.ada Subject: Beginner: Unchecked Deallocation Date: 17 Dec 2001 19:35:50 -0800 Organization: http://groups.google.com/ Message-ID: NNTP-Posting-Host: 217.128.41.80 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1008646550 22452 127.0.0.1 (18 Dec 2001 03:35:50 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 18 Dec 2001 03:35:50 GMT Xref: archiver1.google.com comp.lang.ada:18037 Date: 2001-12-18T03:35:50+00:00 List-Id: Hi all I'm quite new to ADA, ( a few weeks) and I'm trying to write some code for a monodirectional linked list. I've done several function which satisfies me, althought I think my style is not in the Ada phylosophy. The first true problem i've encountered is this one: I want to destroy my linked list, so i would like to free each link in the list. I think that I have to use Ada.Unchecked.Deallocation() My procedure: procedure Free is new Ada.Unchecked_Deallocation (Liste, Liste_Acs); works fine when I put this code directly in the main program, but that's not my goal; I didn't manage to put this procedure, like the other functions, in the body and in the specification parts of my package. When I try to do that, i got this error: package body LCM is | >>> missing body for "Free" declared at lcm.ads:28 I don't understand (maybe because of misunderstanding of the Generic concept ?) Is this procedure supposed to have a "body" ? I thought the body was provided by the instanciation of the generic procedure ? (I'm not sure about the exact terms) Thanks for any help or commments on my code ! (I think my code is clear enough not to translate the name of my functions into english) Here come my code: /*************************************************************** * FICHIER LCM.ADS * \*************************************************************** package LCM is type Liste; type Liste_Acs is access Liste; type Liste is record Item : Integer; Suiv : Liste_Acs; end record; Liste_Vide: exception; function Insere_Tete (Ls : in Liste_Acs; Item : in Integer ) return Liste_Acs; function Insere_Ordre (Ls : in Liste_Acs; Item : Integer ) return Liste_Acs; procedure Affiche (Ls : in Liste_Acs ); function Supprime_Tete (Ls: in Liste_Acs) return Liste_Acs; procedure Free; end LCM; /*************************************************************** * FILE LCM.ADB * \*************************************************************** with Ada.Text_IO; with Ada.Unchecked_Deallocation; package body LCM is function Insere_Tete ( Ls : in Liste_Acs; Item : in Integer ) return Liste_Acs is begin return new Liste'(Item, Ls); end Insere_Tete; function Insere_Ordre ( Ls : in Liste_Acs; Item : Integer ) return Liste_Acs is begin if Ls=null then return Insere_Tete(Ls,Item); elsif Item <= Ls.Item then return Insere_Tete(Ls,Item); else return new Liste'(Ls.Item, Insere_Ordre(Ls.Suiv,Item)); end if; end Insere_Ordre; function Supprime_Tete (Ls: in Liste_Acs) return Liste_Acs is begin if Ls=null then raise Liste_Vide; else return Ls.Suiv; end if; -- I would like to use the free() procedure Here, of course end Supprime_Tete; procedure Affiche ( Ls : in Liste_Acs ) is procedure Affiche2 ( Ls : in Liste_Acs ) is begin if Ls/=null then begin Ada.Text_IO.Put(Integer'Image(Ls.Item)); Affiche2(Ls.Suiv); end; end if; end Affiche2; begin Ada.Text_IO.Put('('); Affiche2(Ls); Ada.Text_IO.Put(" )"); Ada.Text_IO.New_Line; end Affiche; procedure Free is new Ada.Unchecked_Deallocation (Liste, Liste_Acs); --gnatmake complains that there is no body here end LCM; -- b@v