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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,40d697764033dbdb X-Google-Attributes: gid103376,public From: "Norman H. Cohen" Subject: Re: types in procedure arguments Date: 1996/10/01 Message-ID: <3251278D.516D@watson.ibm.com>#1/1 X-Deja-AN: 186465617 references: <5268qg$r1t@noc2.drexel.edu> <52piii$8n7@noc2.drexel.edu> content-type: text/plain; charset=us-ascii organization: IBM Thomas J. Watson Research Center mime-version: 1.0 reply-to: ncohen@watson.ibm.com newsgroups: comp.lang.ada x-mailer: Mozilla 3.0 (Win95; I) Date: 1996-10-01T00:00:00+00:00 List-Id: Chris Papademetrious wrote: > with Tst_Double_List; -- double linked-list package > with Tst_Vectors; > > package Tst_Best_Congruence is > > package Vec_List is new Tst_Double_List(ELEMENT_OBJECT => > Tst_Vectors.Vector); > > procedure Best_Congruence > ( > List: in out Vec_List.LIST_ID > ); > > end Tst_Best_Congruence; > generic > type ELEMENT_OBJECT is private; > package Tst_Double_List is > type LIST_ID is limited private; > private > type LIST_ID is > record > Item1, Item2, Item3: ELEMENT_OBJECT; > end record; > end Tst_Double_List; > package Tst_Vectors is > type Vector is array (0..9) of Float; > end Tst_Vectors; > with Tst_Double_List; -- double linked-list package > with Tst_Best_Congruence; > with Tst_Vectors; > > procedure Tst is > > package Vec_List is new Tst_Double_List(ELEMENT_OBJECT => > Tst_Vectors.Vector); > > L: Vec_List.LIST_ID; > > begin > > Tst_Best_Congruence.Best_Congruence(L); > > end Tst; > package body Tst_Best_Congruence is > > procedure Best_Congruence > ( > List: in Point_List.LIST_ID > ) is > begin > List := List; > end Best_Congruence; > > end Tst_Best_Congruence; This is what I thought the problem was. As you noted in another post, each instantiation package Instance is new Tst_Double_List(T); creates a NEW type Instance.List_ID, even if the generic actual parameter T is the same in both cases and even if the instances (declared in different declarative regions) have the same name. You have created one package named Vec_List nested inside the package Tst_Best_Congruence and a completely distinct package named Vec_List nested inside the procedure Tst. Each of these packages provides a distinct (although structurally identical) type named List_ID. (Perhaps you have experience with C++ templates, instances of which are uniquely identified by the template name and the template arguments. Ada generic templates do not work that way. An instance of an Ada generic template comes into existence only as the result of an explicit generic instantiation, and it is possible to create several distinct instances with the same generic actual parameters.) Your solution, as I sketched in my previous note, is to declare ONE instance of Tst_Double_List, in a compilation unit consisting only of the generic instantiation: with Tst_Double_List, Tst_Vectors; package Vec_List is new Tst_Double_List(ELEMENT_OBJECT => Tst_Vectors.Vector); This is, in effect, the declaration of a separately compiled package named Vec_List. Now you can write with Vec_List; package Tst_Best_Congruence is procedure Best_Congruence (List: in out Vec_List.List_ID); end Tst_Best_Congruence; and with Vec_List, Tst_Best_Congruence; procedure Tst is L: Vec_List.List_ID; begin Tst_Best_Congruence.Best_Congruence(L); end Tst; The with clauses for Vec_List on Tst_Best_Congruence and Tst now reference the SAME instance of Tst_Double_List. -- Norman H. Cohen mailto:ncohen@watson.ibm.com http://www.research.ibm.com/people/n/ncohen