comp.lang.ada
 help / color / mirror / Atom feed
From: Stapler <spam.magnet@yahoo.com>
Subject: Package instantiation and automatic de-allocation.
Date: Mon, 23 Dec 2002 04:42:05 GMT
Date: 2002-12-23T04:42:05+00:00	[thread overview]
Message-ID: <xuwN9.431253$P31.150740@rwcrnsc53> (raw)

Alright, I'm running into a bit of wall here.

I can get my package to work, but I cant get it to work the way I want it
to.

Basically, as I understand it, if I declare something such as

	package foo is new generic_stack(Size, Integer);

Then it wont be de-allocated when it goes out of scope(like at the end of
a declare block) like it should be. This is assuming I've declared it in
the declare section of the declare block. 

Further more I can't "use" generic_stack and then declare a variable such
as

	My_Stack : Stack(Size, Integer);

because language rules wont allow me to "use" a generic_package.

I've tried all sorts of things...
	with gen_stack;

		My_Stack : gen_stack.Stack(Size, Integer);

		My_Stack : new gen_stack.Stack(Size, Integer);

		My_Stack : Blah blah blah.


Heres the package spec, any pointers would be helpful.


generic
	Size : Positive;
	type Item is private;
	
package gen_stack is
	
	Stack_Overflow : exception;
	Stack_Underflow : exception;
	
	procedure Push( X : in Item);
	function Pop return Item;
	function Is_Full return Boolean; -- These functions simply export 
	function Is_Empty return Boolean;-- The Full, Empty fields of the stack.
	
private

	subtype Stack_range is positive range 1..Size;
	type Item_array is array(positive range 1..Size) of Item;
	
	type Stack is limited record
		Elements : Item_Array;
		Top : Stack_range;
		Full, Empty : Boolean;
	end record;
	
end gen_stack;


Basically I want to figure out how to instantiate this within a program
without having to dick with Unchecked_Deallocation. i.e. I want to be
able to assume that it will be de-allocated at then "end" of a declare
block, whether a procedure or an inline "declare" region.

Currently I have to go ...

	package My_Stack is new gen_stack(Size, Foo_Type);


Any pointers would be appreciated.

Stapler



             reply	other threads:[~2002-12-23  4:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-23  4:42 Stapler [this message]
2002-12-23  5:09 ` Package instantiation and automatic de-allocation James S. Rogers
2002-12-23  6:22   ` tmoran
2002-12-24 21:57 ` Stapler
     [not found]   ` <j1cbua.fpc.ln@beastie.ix.netcom.com>
2002-12-25 23:56     ` Stapler
     [not found]       ` <amndua.f24.ln@beastie.ix.netcom.com>
2003-01-13 15:43         ` John English
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox