comp.lang.ada
 help / color / mirror / Atom feed
From: Reinert Korsnes <a@b.no>
Subject: Question on initialization of packages
Date: Tue, 17 Jun 2008 10:07:43 +0200
Date: 2008-06-17T10:07:43+02:00	[thread overview]
Message-ID: <y4adnXtddsFN7crV4p2dnAA@telenor.com> (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;




             reply	other threads:[~2008-06-17  8:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-17  8:07 Reinert Korsnes [this message]
2008-06-17  8:50 ` Question on initialization of packages 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
replies disabled

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