From: bilbo@volcanomail.com (Antoine Lec.)
Subject: Beginner: Unchecked Deallocation
Date: 17 Dec 2001 19:35:50 -0800
Date: 2001-12-18T03:35:50+00:00 [thread overview]
Message-ID: <d442bc8e.0112171935.30eb28b1@posting.google.com> (raw)
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
next reply other threads:[~2001-12-18 3:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-12-18 3:35 Antoine Lec. [this message]
2001-12-18 14:00 ` Beginner: Unchecked Deallocation Mark Doherty
2001-12-18 22:17 ` Antoine Lec.
2001-12-20 4:39 ` Patrick Hohmeyer
2001-12-20 10:07 ` Antoine Lec.
2001-12-20 4:54 ` Steve Doiel
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox