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 autolearn=ham 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 22:22:44 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn14feed!worldnet.att.net!204.127.198.204!attbi_feed4!attbi.com!rwcrnsc51.ops.asp.att.net.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Package instantiation and automatic de-allocation. References: X-Newsreader: Tom's custom newsreader Message-ID: NNTP-Posting-Host: 12.234.13.56 X-Complaints-To: abuse@attbi.com X-Trace: rwcrnsc51.ops.asp.att.net 1040624564 12.234.13.56 (Mon, 23 Dec 2002 06:22:44 GMT) NNTP-Posting-Date: Mon, 23 Dec 2002 06:22:44 GMT Organization: AT&T Broadband Date: Mon, 23 Dec 2002 06:22:44 GMT Xref: archiver1.google.com comp.lang.ada:32221 Date: 2002-12-23T06:22:44+00:00 List-Id: > 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. That's true if you want to allow multiple Stack objects, perhaps arrays of Stacks, etc. Sometimes you really only want one or very few objects, so one/generic instantiation is good. For instance, say you have a space rocket with two similar radios, one of which talks to Earth and the other to your Moon base. You might then generic Hardware_Port : Natural; package Communications is ... procedure Send(...); procedure Receive(...); ... package Earth is new Communications(Port=>16#378#); package Moon is new Communications(Port=>16#278#); Then you can say Earth.Send(...); Moon.Receive(...); But if you had 4 moon bases, you would have to package Moon_1 is new Communications(... package Moon_2 is new Communications(... package Moon_3 is new Communications(... package Moon_4 is new Communications(... you couldn't make an array Moon(1 .. 4). > without having to dick with Unchecked_Deallocation. If you never say "X := new ...", you never have to use Unchecked_Deallocation. If you declare an object or do a generic instantiation in a declare, it will automagically be deallocated when you leave that scope.