comp.lang.ada
 help / color / mirror / Atom feed
* Re: Access types for procedures
  1997-12-15  0:00 Access types for procedures Mark Rutten
@ 1997-12-15  0:00 ` Jon S Anthony
  0 siblings, 0 replies; 2+ messages in thread
From: Jon S Anthony @ 1997-12-15  0:00 UTC (permalink / raw)



Mark Rutten <Mark.Rutten@dsto.defence.gov.au> writes:

> -- 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);

Put this in a library level package.  It can be the entire package.

> 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);

By instantiating the generic in your main procedure, the resulting
Effect procedure has a deeper (1 level) scope than the procedure
access type which is defined in the (presumably) library level package
with the message decls and such.  This causes the access level
mismatch.

> 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.

Right - the resulting procedure from the instantiation is still at
library level in this case.

/Jon

-- 
Jon Anthony
Synquiry Technologies, Ltd., Belmont, MA 02178, 617.484.3383
"Nightmares - Ha!  The way my life's been going lately,
 Who'd notice?"  -- Londo Mollari




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Access types for procedures
@ 1997-12-15  0:00 Mark Rutten
  1997-12-15  0:00 ` Jon S Anthony
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Rutten @ 1997-12-15  0:00 UTC (permalink / 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







^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-12-15  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-12-15  0:00 Access types for procedures Mark Rutten
1997-12-15  0:00 ` Jon S Anthony

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