I'm a C programmer trying to implement a data structure that I have implemented previously in C, but in Ada. After banging my head into the wall a few times, I've decided to come ask the stack gods for assistance.
procedure Ok is
type Node;
type Node is record
Next : access Node;
Prev : access Node;
end record;
begin
declare
a : aliased Node;
begin
a.Prev := a'Access;
end;
end;
Compilation fails because due to:
ok.adb:14:19: non-local pointer cannot point to local object which doesn't make sense to me. Which pointer is non-local? (it works if a is defined in procedure scope).
Then
procedure Ok is
type Node;
type Node is record
Next : access Node;
Prev : access Node;
end record;
procedure func(NodeOne : aliased in out Node) is
NodeP : access Node := NodeOne'Access;
begin
NodeOne.Next := NodeP;
NodeOne.Prev := NodeP;
end func;
begin
declare
a : aliased Node;
begin
func(a);
end;
end;
This one gets a runtime accessibility check failure on the
NodeOne.Next := NodeP; line
Why is the accessibility not correct?