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 Path: g2news1.google.com!postnews.google.com!c65g2000hsa.googlegroups.com!not-for-mail From: christoph.grein@eurocopter.com Newsgroups: comp.lang.ada Subject: Re: Question on initialization of packages Date: Tue, 17 Jun 2008 03:18:22 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <1pok6brk3yyxf$.ct5gwnf4g97p$.dlg@40tude.net> NNTP-Posting-Host: 80.156.44.178 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1213697902 5499 127.0.0.1 (17 Jun 2008 10:18:22 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 17 Jun 2008 10:18:22 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c65g2000hsa.googlegroups.com; posting-host=80.156.44.178; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1),gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 webwasher (Webwasher 6.7.0.3295) Xref: g2news1.google.com comp.lang.ada:736 Date: 2008-06-17T03:18:22-07:00 List-Id: On 17 Jun., 10:50, "Dmitry A. Kazakov" wrote: > 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: > > > =A0 type Stack is access Cell; > > And > > =A0 =A0Send_Stack : Message_Stack_p.Stack; -- This will be null =3D empty But N is undefined, so you have an empty stack with an undefined number of elements. There is no way to make it visible to users that the stack is empty after declaration of a stack object if you hide the implementation. You must state this as a comment; this belongs to the contract of the ADT and you must implement it fulfilling the contract: private type Cell; type Stack is access Cell; type Cell is record Next : Stack; N : Integer :=3D 0; -- better use Natural here, or will you ever have a negative number of elements? Value: Item; end record; end Stacks; Your stack should be limited private - or do you want to copy stack objects? Then you must be careful that deep copies are made. With this design, you have no control over copying. A copy of a stack will be a shallow copy. For freeing cells, see Ada.Unchecked_Deallocation.