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-Thread: 103376,5e53057e86953953 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!out04b.usenetserver.com!news.usenetserver.com!in04.usenetserver.com!news.usenetserver.com!nlpi057.nbdc.sbc.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Question on initialization of packages Date: Tue, 17 Jun 2008 10:29:12 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1213712952 30112 192.74.137.71 (17 Jun 2008 14:29:12 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Tue, 17 Jun 2008 14:29:12 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:3nmCBfdJMG9jThgPOqS81ATBjL8= Xref: g2news1.google.com comp.lang.ada:741 Date: 2008-06-17T10:29:12-04:00 List-Id: Reinert Korsnes writes: > I try to use a stack in my Ada program. > > Assume the package definition given below, > and the follow code in my program: > > type Message_t; > type Message_ta is access Message_t; > package Message_Stack_p is new Stacks(Message_ta); > Send_Stack : Message_Stack_p.Stack; > > > Question: How can I be sure that "Send_Stack" is empty > at the start of the program execution ? > > How can I make explicite that "Send_Stack" is empty in this case ? Here's one way: Declare Stack like this: type Stack(<>) is limited private; The "(<>)" means clients cannot declare objects without initializing them. The "limited" means clients cannot copy them. Declare the full type like this: type Stack is limited record ... -- pointer to first cell, and count can go here end record; Declare a constructor function: function Empty_Stack return Stack; Declare other constructor functions if you want. Then: Send_Stack: Message_Stack_p.Stack := Message_Stack_p.Empty_Stack; Note that this works only in Ada 2005 mode. - Bob