comp.lang.ada
 help / color / mirror / Atom feed
* Access to procedure and generics
@ 2012-08-28  9:46 Markus Schöpflin
  2012-08-28 10:20 ` Egil Høvik
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Markus Schöpflin @ 2012-08-28  9:46 UTC (permalink / 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



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

end of thread, other threads:[~2012-09-07 12:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-28  9:46 Access to procedure and generics Markus Schöpflin
2012-08-28 10:20 ` 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

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