comp.lang.ada
 help / color / mirror / Atom feed
* Question on initialization of packages
@ 2008-06-17  8:07 Reinert Korsnes
  2008-06-17  8:50 ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Reinert Korsnes @ 2008-06-17  8:07 UTC (permalink / raw)


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 ?

reinert

------------------------------------------------------------------
generic
  type Item is private;
package Stacks is
  type Stack is private;

  procedure Push(S: in out Stack; X:  in Item);
  procedure  Pop(S: in out Stack; X: out Item);
  function N_elements(S : Stack) return Integer;

private
  type Cell;
  type Stack is access Cell;
  type Cell is
    record
      Next : Stack;
      N    : Integer;
      Value: Item;
    end record;
end Stacks;

---

package body Stacks is

  procedure Push(S: in out Stack; X: in Item) is
  begin
    if S /= null then
       S := new Cell'(S,S.N+1,X);
    else
       S := new Cell'(S,1,X);
    end if;
  end;

  procedure Pop(S: in out Stack; X: out Item) is
  begin
    X := S.Value;
    S := S.Next;
  end;

  function N_elements(S: Stack) return Integer is
  begin
    if S /= null then
       return S.N;
    else
       return 0;
    end if;
  end;

end Stacks;




^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2008-06-17 18:29 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2008-06-17 16:39 ` Jeffrey R. Carter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox