I'm having some issues with generics in Ada. Given the below example, gnatmake results in:
g_package.adb:13:33: 'Access attribute not allowed in generic body
g_package.adb:13:33: because access type "t_callback_p" is declared outside generic unit (RM 3.10.2(32))
g_package.adb:13:33: move 'Access to private part, or (Ada 2005) use anonymous access type instead of "t_callback_p"
gnatmake: "g_package.adb" compilation error
With the assumption that the external package cannot be changed, is there a way to solve this? I get the reason for the error message in the first place (compiler doesn't know the proper type of the generic package, but it's a bit annoying when the passed function in question doesn't touch any part of the generic..)
g_package.adb
with Ada.Text_IO; use Ada.Text_IO;
with external;
package body g_package is
procedure quix (f : String) is
begin
Put_Line ("Does a thing");
end quix;
procedure foo (bar : String) is
begin
Put_Line ("baz" & bar & Boolean'Image(flag));
external.procedure_f (quix'Access);
end foo;
end g_package;
g_package.ads
generic
flag : Boolean;
package g_package is
procedure foo (bar : String);
end g_package;
external.ads
package external is
type t_callback_p is access procedure (s : String);
procedure procedure_f (proc : t_callback_p);
end external;