comp.lang.ada
 help / color / mirror / Atom feed
From: Mark Rutten <Mark.Rutten@dsto.defence.gov.au>
Subject: Access types for procedures
Date: 1997/12/15
Date: 1997-12-15T00:00:00+00:00	[thread overview]
Message-ID: <3494A820.9E33032F@dsto.defence.gov.au> (raw)


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







             reply	other threads:[~1997-12-15  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-12-15  0:00 Mark Rutten [this message]
1997-12-15  0:00 ` Access types for procedures Jon S Anthony
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox