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=-0.3 required=5.0 tests=BAYES_00,LOTS_OF_MONEY, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c6e5a27ff403a94d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-22 21:09:31 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn14feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!not-for-mail Reply-To: "James S. Rogers" From: "James S. Rogers" Newsgroups: comp.lang.ada References: Subject: Re: Package instantiation and automatic de-allocation. X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: Date: Mon, 23 Dec 2002 05:09:31 GMT NNTP-Posting-Host: 12.86.38.69 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1040620171 12.86.38.69 (Mon, 23 Dec 2002 05:09:31 GMT) NNTP-Posting-Date: Mon, 23 Dec 2002 05:09:31 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:32219 Date: 2002-12-23T05:09:31+00:00 List-Id: "Stapler" wrote in message news:xuwN9.431253$P31.150740@rwcrnsc53... > 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... Your package below does not work because it lacks a public declaration for your Stack type. Once you have a name for the type you must pass an instance of that type to each function and procedure. Ada does not have an impicit "this" variable like C++ or Java. > 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 > type Stack is private; > Stack_Overflow : exception; > Stack_Underflow : exception; > procedure Push( X : in Item : Onto : in out Stack); function Pop(From : Stack) return Item; function Is_Full(Item : Stack) return Boolean; -- These functions simply export function Is_Empty(Item : Stack) 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. In the example above an instantiation does not allocate an object. Creating an instance of the generic package is separate from creating an instance of a stack object from an instantiated package. > > Currently I have to go ... > > package My_Stack is new gen_stack(Size, Foo_Type); This is correct. It instantiates the package with a size of Size and a type of Foo_Type. Next you want to create an instance of the stack from that package: My_Foo_Stack : My_Stack.Stack; This will be deallocated when the block it is declared in goes out of scope. Jim Rogers