From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5e53057e86953953,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!nntp.telenor.com!news.telenor.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 17 Jun 2008 03:07:43 -0500 From: Reinert Korsnes Subject: Question on initialization of packages Newsgroups: comp.lang.ada Date: Tue, 17 Jun 2008 10:07:43 +0200 User-Agent: KNode/0.10.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit Message-ID: X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-CgirDptvvwznSdNWG7PNAh6GoHlLU9tO9l6jRUd5ko8RJyW2eUn+JgzFyAksVJcQnWQstiW08hozHAZ!2ZXH+LMW5i7th6crF+XW+tkEfFsNPlW4GMpoob75aRE2PyOFIMhKdof+u65kTL4mUonnO/CQEbU= X-Complaints-To: news-abuse@telenor.net X-DMCA-Complaints-To: news-abuse@telenor.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.39 Xref: g2news1.google.com comp.lang.ada:733 Date: 2008-06-17T10:07:43+02:00 List-Id: 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;