I'm tryin to implement a protected object in Ada which has a reference to a procedure it owns. This is my code:
procedure sm is
type StateHandler is access procedure;
protected Motor is
private
procedure proc;
x : StateHandler := proc'Access;
end Motor;
protected body Motor is
procedure proc is
begin
Put_Line("HELLO WORLD");
end proc;
end Motor;
begin
Put_Line("ASD");
end sm;
I have tried Motor.proc'Access as well.
When I try to compile this code, I obtain the following errors:
sm.adb:18:29: subprogram "proc" has wrong convention
sm.adb:18:29: does not match "StateHandler" declared at line 11
sm.adb:18:29: probable missing pragma Convention for "StateHandler"
gnatmake: "sm.adb" compilation error
Makefile:3: recipe for target 'ADA' failed
make: *** [ADA] Error 4
I have tried many ways to solve it but I am unable.
pragma Convention (C, proc);afher the declaration ofproc. It makes sense that protected procedures will have different calling conventions from normal ones, and accessing a protected procedure via a non-protected (so to speak) access type may be problematic ... but that's as far as I can get, offhand. - user_1818839