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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f5b0e4b29b2f0c99 X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: Who is right? Gnat or http://www.adahome.com/articles/1998-02/ar_lessons95.html? Date: 1999/04/07 Message-ID: #1/1 X-Deja-AN: 463543024 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.burl.averstar.com References: <01be80c2$114e0890$c24d3a8b@m04w0588> Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1999-04-07T00:00:00+00:00 List-Id: Daniel Wengelin (dawe@celsiustech.se) wrote: : When looking around for some infomration about OOP I came across the : article http://www.adahome.com/articles/1998-02/ar_lessons95.html. : When skimming through, I noted the following section : ----------------------------------------- COPY FROM ADAHOME : --------------------------------- : The ability to pass subprograms as parameters is one of the nicest features : of Ada 95 (it didn't exist in Ada 83). But accessibility rules make it : useless within a multi-tasking program. Indeed, access to a local procedure : cannot be used as a parameter of a more globally declared procedure (e.g. a : class method). ... : ... : I gave the code a try with Gnat 3.11 as follows. : generic : type Item_T is private; : package List is : type Node; : type Object is access Node; : type Node is record : I : Item_T; : Next:Object; : end record; : type Action_Proc is access procedure : (I : in out Item_T); : procedure Iterate : (The_Action : Action_Proc; : Through_List : Object); : end List; : --------------------------- : package body List is : procedure Iterate : (The_Action : Action_Proc; : Through_List : Object) : is : Current : Object := Through_List; : begin : while Current /= null loop : The_Action(Current.I); : Current := Current.Next; : end loop; : end Iterate; : end List; : ------------------------ : procedure List_Test is : procedure Print (C: in out Character) is : begin : Ada.Text_Io.Put(C); : Ada.Text_Io.New_Line; : end Print; : package C_List is new List(Character); : The_List : C_List.Object := null; : begin : for I in Character range 'a' .. 'e' loop : The_List := new C_List.Node'(I, The_List); : end loop; : C_List.Iterate (Print'Access, The_List); : end List_Test; : The above source compiled and ran without any problems. So, did I : misunderstand or is Gnat wrong or is the article in AdaHome wrong? The critical difference between your code and the code on AdaHome is that your instantiation of the generic is at the same accessibility level as the function named in the prefix to 'Access. The code in AdaHome might be able to work the same way, by moving their instantiation so that it is inside the outer subprogram. But there also may be reasons why they didn't want the instantiation itself nested. In any case, one way to address these "multitasking" problems is to add an additional class-wide parameter through which additional data can be passed through to a global function. : thanks. : Daniel -- -Tucker Taft stt@averstar.com http://www.averstar.com/~stt/ Technical Director, Distributed IT Solutions (www.averstar.com/tools) AverStar (formerly Intermetrics, Inc.) Burlington, MA USA