Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Question on ini...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 14 Topic 5758 of 5881
Post > Topic >>

Question on initialization of packages

by Reinert Korsnes <a@[EMAIL PROTECTED] > Jun 17, 2008 at 10:07 AM

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;
 




 14 Posts in Topic:
Question on initialization of packages
Reinert Korsnes <a@[EM  2008-06-17 10:07:43 
Re: Question on initialization of packages
"Dmitry A. Kazakov&q  2008-06-17 10:50:57 
Re: Question on initialization of packages
Reinert Korsnes <a@[EM  2008-06-17 11:14:59 
Re: Question on initialization of packages
"Dmitry A. Kazakov&q  2008-06-17 12:26:08 
Re: Question on initialization of packages
Reinert Korsnes <a@[EM  2008-06-17 14:03:55 
Re: Question on initialization of packages
Georg Bauhaus <rm.dash  2008-06-17 12:39:35 
Re: Question on initialization of packages
"Jeffrey R. Carter&q  2008-06-17 16:41:16 
Re: Question on initialization of packages
Robert A Duff <bobduff  2008-06-17 13:08:08 
Re: Question on initialization of packages
"Dmitry A. Kazakov&q  2008-06-17 19:33:47 
Re: Question on initialization of packages
"Jeffrey R. Carter&q  2008-06-17 18:29:40 
Re: Question on initialization of packages
christoph.grein@[EMAIL PR  2008-06-17 03:18:22 
Re: Question on initialization of packages
Martin <martin.dowie@[  2008-06-17 07:12:38 
Re: Question on initialization of packages
Robert A Duff <bobduff  2008-06-17 10:29:12 
Re: Question on initialization of packages
"Jeffrey R. Carter&q  2008-06-17 16:39:17 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 15:32:23 CDT 2008.