comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: "accessibility check failed" on Node
Date: Thu, 27 Jun 2013 09:24:52 +0100
Date: 2013-06-27T09:24:52+01:00	[thread overview]
Message-ID: <ly8v1wklkb.fsf@pushface.org> (raw)
In-Reply-To: kqfrrv$lsb$1@news2.open-news-network.org

Thomas Schmidt <TC.Schmidt@gmx.net> writes:

>   function findNode2
>     (graph : DirectedGraph;
>      aNode : access Node'Class)
>      return  Node_Class_Access is

I spent quite some time making a compilable example. It would have been
kind of you to have done the same!

The call in

     position : constant NodeSets.Cursor :=
       graph.nodes.Find (aNode.all'Access);

seemed a bit magical (a respected colleague said that he found himself
using ".all.Access" as a band-aid for shutting up the compiler's
complaints about type mismatches without bothering to understand
them). So I tried

      N : constant Node_Class_Access := Node_Class_Access (aNode);
      position : constant NodeSets.Cursor := graph.nodes.Find (N);

which moved the "accessibility check failed" to the "N :=" line.

I made a findNode3 with the type of aNode changed to Node_Class_Access:

   function findNode3
     (graph : DirectedGraph;
      aNode : Node_Class_Access)
     return  Node_Class_Access is

      position : constant NodeSets.Cursor := graph.nodes.Find (aNode);

   begin
      if position /= NodeSets.No_Element then
         return Nodesets.Element (position);
      else
         raise No_Element with "failed in Findnode3";
      end if;
   end findNode3;

Calling findNode3 with an aliased local Neuron now requires me to use
'Unchecked_Access, or I get the compilation error "non-local pointer
cannot point to local object".

As to your original question, why "Node (aNode.all)'Access" should be OK
while "aNode.all'Access" isn't .. I expect the answer is something deep,
and I'd go along with Jeff Carter about avoiding the use of anonymous
access types.


  parent reply	other threads:[~2013-06-27  8:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-26 23:01 "accessibility check failed" on Node Thomas Schmidt
2013-06-26 23:45 ` Shark8
2013-06-26 23:58 ` Jeffrey Carter
2013-06-27  7:36 ` Georg Bauhaus
2013-06-27  7:49 ` Dmitry A. Kazakov
2013-06-27  8:24 ` Simon Wright [this message]
2013-06-27 11:19   ` Thomas Schmidt
2013-06-27 12:49     ` Frédéric Praca
2013-06-27 14:36     ` Eryndlia Mavourneen
2013-06-27 17:31       ` Jeffrey Carter
2013-06-27 17:45         ` Simon Wright
2013-06-27 23:26           ` Randy Brukardt
2013-06-28  0:52             ` Jeffrey Carter
2013-06-27 18:33         ` Eryndlia Mavourneen
2013-06-27 20:31           ` Jeffrey Carter
2013-06-27 23:29             ` Randy Brukardt
2013-06-27 14:51     ` Shark8
2013-06-27 17:29     ` Jeffrey Carter
2013-06-27 10:46 ` Stephen Leake
replies disabled

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