* How to make a generic controlled type?
@ 1999-09-24 0:00 Anders Gidenstam
1999-09-24 0:00 ` Ehud Lamm
0 siblings, 1 reply; 3+ messages in thread
From: Anders Gidenstam @ 1999-09-24 0:00 UTC (permalink / raw)
Hello!
I'm trying to make a generic list package, and since I implement
the list as a linked list I want to use a controlled type for it to prevent
memory leaks. However GNAT (and I assume Ada) doesn't allow me to declare
a controlled type inside a generic package. So I wonder if someone has a
nice solution to this problem.
with Ada.Finalization;
generic
type Element_Type is private;
package List is
type List is new Ada.Finalization.Limited_Controlled with private;
-- Insert E at the current location.
procedure Insert (L: in out List;
E: in Element_Type);
...
/Anders
--------------------------------------------
"A well-written program is its own heaven;
a poorly-written program is its own hell."
- The Tao of Programming
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to make a generic controlled type?
1999-09-24 0:00 How to make a generic controlled type? Anders Gidenstam
@ 1999-09-24 0:00 ` Ehud Lamm
1999-09-26 0:00 ` David Botton
0 siblings, 1 reply; 3+ messages in thread
From: Ehud Lamm @ 1999-09-24 0:00 UTC (permalink / raw)
The following seems to compile fine on my system. What problem do you have
exactly?
with Ada.Finalization;
generic
type Element_Type is private;
package Bug_List is
type List is new Ada.Finalization.Limited_Controlled with private;
-- Insert E at the current location.
procedure Insert (L: in out List;
E: in Element_Type);
private
type Node;
type Link is access Node;
type Node is record V:Element_Type; N:Link; end record;
type List is new Ada.Finalization.Limited_Controlled with
record
H:Link;
end record;
procedure Initialize(L:in out List);
procedure Finalize (L:in out List);
end;
By the way, just a day ago I submitted an example of a "simple controlled
list" to AdaPower (to accompany my example of a simple polymorphic list).
I don't think it is there yet but I guess it should be soon. You may want
to take it and start from there.
Ehud Lamm mslamm@mscc.huji.ac.il
http://purl.oclc.org/NET/ehudlamm <== My home on the web
Check it out and subscribe to the E-List- for interesting essays and more!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1999-09-26 0:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-24 0:00 How to make a generic controlled type? Anders Gidenstam
1999-09-24 0:00 ` Ehud Lamm
1999-09-26 0:00 ` David Botton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox