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, REPLYTO_WITHOUT_TO_CC autolearn=no 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!feeder.news-service.com!hq-usenetpeers.eweka.nl!81.171.88.9.MISMATCH!ramfeed2.eweka.nl!eweka.nl!lightspeed.eweka.nl!npeer.de.kpn-eurorings.net!npeer-ng1.kpn.DE!news.netcologne.de!newsfeed-hp2.netcologne.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Question on initialization of packages Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Tue, 17 Jun 2008 10:50:57 +0200 Message-ID: <1pok6brk3yyxf$.ct5gwnf4g97p$.dlg@40tude.net> NNTP-Posting-Date: 17 Jun 2008 10:50:57 CEST NNTP-Posting-Host: 13d405d1.newsspool3.arcor-online.net X-Trace: DXC=RH]VeS1NSYKgj[ZPFj7ehOMcF=Q^Z^V3H4Fo<]lROoRA8kFC\b4nF[6LHn;2LCVN7enW;^6ZC`DIXm65S@:3>Ok?AcY0JdTMI X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:734 Date: 2008-06-17T10:50:57+02:00 List-Id: On Tue, 17 Jun 2008 10:07:43 +0200, Reinert Korsnes wrote: > 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 ? Hmm, "sure" in which sense? To make it visible for the reader? To specify in the contract of Stack that it is initially empty? As for implementation you posted, the stack is empty, because instances of access types are initialized with null (when not explicitly initialized otherwise). Below you declare: > type Stack is access Cell; And Send_Stack : Message_Stack_p.Stack; -- This will be null = empty Now side comments: 1. > procedure Pop(S: in out Stack; X: out Item) is > begin > X := S.Value; > S := S.Next; > end; This is a memory leak. If you allocated a stack element on push, you should free it on pop. 2. Package initialization is achieved as follows: package body P is ... begin ... -- Initialize package stuff end P; 3. Package initialization cannot help you here, because the package declares an abstract data type of which objects can be created long after the package itself was elaborated (initialized). 4. You have messages. Pointers to messages. These pointers are copied into dynamically allocated linked list called stack. How are you going to maintain this? Do you want to prevent messages from being copied? Then you should reconsider the design of messages allowing their queuing without stacks. Alternatively, do you want to copy messages upon queueing (to marshal them)? Then the queue should deal with unconstrained objects: generic type Message (<>) is private; package Queue is ... -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de