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.3 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d3b3a6fb3be6d395 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-11-24 23:40:03 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!fr.usenet-edu.net!usenet-edu.net!enst.fr!not-for-mail From: "Grein, Christoph" Newsgroups: comp.lang.ada Subject: Re: A tiny little integer stack package from a novice. Date: Mon, 25 Nov 2002 08:33:27 +0100 (MET) Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: TEXT/plain; charset=us-ascii X-Trace: avanie.enst.fr 1038210003 69775 137.194.161.2 (25 Nov 2002 07:40:03 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Mon, 25 Nov 2002 07:40:03 +0000 (UTC) Return-Path: X-Authentication-Warning: mail.eurocopter.com: uucp set sender to using -f Content-MD5: 6F4n4sVtJGjPynsNbon7UQ== X-Mailer: dtmail 1.2.1 CDE Version 1.2.1 SunOS 5.6 sun4u sparc Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.13 Precedence: bulk X-Reply-To: "Grein, Christoph" List-Unsubscribe: , List-Id: comp.lang.ada mail<->news gateway List-Post: List-Help: List-Subscribe: , Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:31206 Date: 2002-11-25T08:33:27+01:00 > with Ada.Unchecked_Deallocation; > generic > > Size : Positive; > > package int_stack is > > type Int_Stack is limited private; > type Stack_Ptr is limited private; Why are these two types visible? There is nothing one can do with them. A user or your package can declare variables of those types, but they will never be used by your package. > > procedure Push(X : in Integer); > procedure Free_Stack; Once you've called Free_Stack, you can never again use it. Is this really what you want? > function Pop return Integer; > > private > > > type Int_Stack is array(1..Size) of Integer; > type Stack_Ptr is access all Int_Stack; > The_Stack : Stack_Ptr := new Int_Stack; -- Provides access for De-allocation of entire stack > -- Is also the sole allocation point for this package. > procedure Free is new Ada.Unchecked_Deallocation(Int_Stack, Stack_Ptr); Why do you use dynamic allocation? There are other possibilities. > end int_stack; > > > > package body int_stack is > > Counter : Positive := 1; > > procedure Push(X : in Integer) is > > begin > > The_Stack.all(Counter) := X; > > Counter := Counter + 1; > What about overflow here or underflow below? > end Push; > > procedure Free_Stack is > > begin > > Free(The_Stack); -- I'm learning to make the commands > -- self-explanatory here. Heh. > > end Free_Stack; > > function Pop return Integer is > > X : Integer := 0; > > begin > Counter := Counter - 1; -- The Counter op is placed here because > -- the Counter variable will point to 1 element > -- past the end of the array on the first > -- call. > X := The_Stack(Counter); > > return X; > > end Pop; > > end int_stack; There is mnre to say, but suffice this for the moment. I think when you ponder about the above, you'll see further enhancement possibilities.