From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Question on initialization of packages
Date: Tue, 17 Jun 2008 10:29:12 -0400
Date: 2008-06-17T10:29:12-04:00 [thread overview]
Message-ID: <wcc3ancceyv.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: y4adnXtddsFN7crV4p2dnAA@telenor.com
Reinert Korsnes <a@b.no> 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
next prev parent reply other threads:[~2008-06-17 14:29 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
2008-06-17 14:29 ` Robert A Duff [this message]
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