From: christoph.grein@eurocopter.com
Subject: Re: Question on initialization of packages
Date: Tue, 17 Jun 2008 03:18:22 -0700 (PDT)
Date: 2008-06-17T03:18:22-07:00 [thread overview]
Message-ID: <c83a3c43-1153-4941-993a-4b6c3c9bf073@c65g2000hsa.googlegroups.com> (raw)
In-Reply-To: 1pok6brk3yyxf$.ct5gwnf4g97p$.dlg@40tude.net
On 17 Jun., 10:50, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
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:
>
> > type Stack is access Cell;
>
> And
>
> Send_Stack : Message_Stack_p.Stack; -- This will be null = 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 := 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.
next prev parent reply other threads:[~2008-06-17 10:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-17 8:07 Question on initialization of packages Reinert Korsnes
2008-06-17 8:50 ` Dmitry A. Kazakov
2008-06-17 9:14 ` Reinert Korsnes
2008-06-17 10:26 ` Dmitry A. Kazakov
2008-06-17 12:03 ` Reinert Korsnes
2008-06-17 14:12 ` Martin
2008-06-17 10:39 ` Georg Bauhaus
2008-06-17 16:41 ` Jeffrey R. Carter
2008-06-17 17:08 ` Robert A Duff
2008-06-17 17:33 ` Dmitry A. Kazakov
2008-06-17 18:29 ` Jeffrey R. Carter
2008-06-17 10:18 ` christoph.grein [this message]
2008-06-17 14:29 ` Robert A Duff
2008-06-17 16:39 ` Jeffrey R. Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox