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,640a63b200daf902,start X-Google-Attributes: gid103376,public From: Mark Rutten Subject: Access types for procedures Date: 1997/12/15 Message-ID: <3494A820.9E33032F@dsto.defence.gov.au>#1/1 X-Deja-AN: 298266842 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Organization: Defence Science & Technology Organisation Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1997-12-15T00:00:00+00:00 List-Id: Hi all, I'm hoping that some of you may be able to help me see why what I'm doing is wrong. A brief summary of the problem is as follows: I have a principal task which I am trying to send a message to. I want to tell this task about a procedure that it can call when a certain event happens, so the message record has an element which is an access type for a particular format of procedure. All of these procedures called from my principal task must be handled in the same way, so I've made most of this generic. The code which makes all this happen has a format along the following lines -- -- Define a procedure to do the message handling. -- procedure blah(msg: in message) is Ada.Text_IO.Put_Line("Message received"); end blah -- -- Instantiate a generic package which is basically going to -- queue up messages on an entry to a task and then -- consecutively call blah with each new message. -- package New_Effector is new G_Effector( in_name=> "output", in_procedure => blah); -- -- Send a message to the principal task to tell it about -- where to find this new procedure -- Msg := Create_Message("output", New_Effector.Effect'Access); Send_Message(Msg); The generic package has a single externally accessible procedure, called Effect, which has the same declarative form as blah, i.e. procedure Effect(msg: in Message); The message declarations are in their own package, which includes the definition of the procedure access type type Effector_Procedure is access procedure(msg: in message); If I insert the above code into my main procedure then I get the following compilation error (I'm using GNAT 3.09 under Solaris2.6 - I do realise we are using an older version of GNAT, we will update in the near future) >>> subprogram must not be deeper than access type where it is referring to New_Effector.Effect'Access. However I can insert the above code into a package and supply a procedure in this package which creates and sends the message. I can then get the same functionality as above by calling this procedure from the main procedure, but then this error does not appear and everything works happily. I don't understand why, which is why I'm asking people who know a lot more about Ada's peculiarities than I do. Thanks, Mark Rutten