From: "Markus Schöpflin" <no.spam@spam.spam>
Subject: Access to procedure and generics
Date: Tue, 28 Aug 2012 11:46:41 +0200
Date: 2012-08-28T11:46:41+02:00 [thread overview]
Message-ID: <k1i41v$sfk$1@speranza.aioe.org> (raw)
Hello,
please consider the following program. What it is trying to achieve (in Ada
95) is that a callback is registered for call as soon as the generic is
instantiated.
---%<---
package CALLBACK is
type CALLBACK_T is access procedure;
procedure REGISTER_CALLBACK(CALLBACK : CALLBACK_T);
end CALLBACK;
--
package body CALLBACK is
procedure REGISTER_CALLBACK(CALLBACK : CALLBACK_T)
is
begin
null;
end;
end CALLBACK;
--
generic
package USE_CALLBACK is
procedure HANDLER;
end USE_CALLBACK;
--
with CALLBACK;
package body USE_CALLBACK
is
procedure HANDLER is
begin
null;
end;
begin
CALLBACK.REGISTER_CALLBACK(HANDLER'Access);
end USE_CALLBACK;
--
with USE_CALLBACK;
procedure TEST is
package FOO is new USE_CALLBACK;
begin
null;
end TEST;
--->%---
When trying to compile this with GNAT 4.4.5 in Ada95 mode, I get the following
error:
> gnatmake -gnat95 test
gcc-4.4 -c -gnat95 test.adb
use_callback.adb:10:38: 'Access attribute not allowed in generic body
use_callback.adb:10:38: because access type "CALLBACK_T" is declared outside
generic unit (RM 3.10.2(32))
use_callback.adb:10:38: move 'Access to private part, or (Ada 2005) use
anonymous access type instead of "CALLBACK_T"
Now, after reading the reference cited by GNAT I think I understand why it
doesn't compile, but I have a hard time figuring out what GNAT means by "move
'Access to private part".
And I'm still at a loss on how to achieve what I actually need, namely
automatically registering a callback as soon as the generic is instantiated.
Any help would be much appreciated.
Regards,
Markus
next reply other threads:[~2012-08-28 9:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-28 9:46 Markus Schöpflin [this message]
2012-08-28 10:20 ` Access to procedure and generics Egil Høvik
2012-08-28 10:22 ` Egil Høvik
2012-08-28 10:32 ` Markus Schöpflin
2012-08-31 14:14 ` Robert A Duff
2012-08-28 10:41 ` Georg Bauhaus
2012-08-28 10:47 ` Markus Schöpflin
2012-08-28 15:57 ` Adam Beneschan
2012-08-28 16:01 ` Adam Beneschan
2012-08-29 3:52 ` Brad Moore
2012-08-29 11:25 ` Markus Schöpflin
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox