From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.albasani.net!reality.xs3.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: accessibility check failed Date: Mon, 30 Nov 2015 17:22:47 -0600 Organization: JSA Research & Innovation Message-ID: References: <3d45e3ed-16ca-4018-bf7b-62830acaca03@googlegroups.com> <44e20a95-703c-4316-8dda-aa2c8d07dfb1@googlegroups.com> <29d3244c-1769-4cb7-8af3-e1b20eb2e1e2@googlegroups.com> NNTP-Posting-Host: rrsoftware.com X-Trace: loke.gir.dk 1448925769 18416 24.196.82.226 (30 Nov 2015 23:22:49 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Mon, 30 Nov 2015 23:22:49 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: news.eternal-september.org comp.lang.ada:28607 Date: 2015-11-30T17:22:47-06:00 List-Id: "Serge Robyns" wrote in message news:29d3244c-1769-4cb7-8af3-e1b20eb2e1e2@googlegroups.com... ... >In my case I'm trying to build an interface to hide implementation details. >The >code provided is using containers as a store but should also be able to use >any >kind of (R)DBMS for all or part of the data. And hence this is where the >beauty of OO comes but does indeed require to use access type to "keep" >track of things. You rarely need explicit access types in an Ada interface, as "in out T" and "access T" are essentially the same for any tagged type T. Ada always allows taking 'Access (or 'Unchecked_Access) of a tagged type parameter. Claw ("Class Library for Ada and Windows", see rrsoftware.com) uses almost no access types in its public interface, yet almost everything is referential under the covers. Works fine, and puts all of the pain on the implementor of the library (where it belongs) and not on the clients (like access types do). (The one place where we had to use an access type was in a single function return where return-by-copy didn't have the proper effect. That's pretty rare.) To answer your original question, once you use anonymous access types, all accessibility checks become dynamic. That is, the accessibility of the actual object is checked, no matter how many levels it's passed through. Most likely, someone is operating on a local object and made a call on the routine that's failing. Bob Duff calls that a "tripping hazard", and it means that you can never reliably save anonymous access parameters outside of the original subprogram (you can do it in the subprogram with a local anonymous access object -- a hack on top of a hack, IMHO). In Ada 2012, you can "protect" an anonymous access with a precondition using a membership test (but warning: these aren't tested in the ACATS and I don't know if anyone has implemented them correctly). Something like: type Global_Access is access all Object; function Something (Acc : access Object; ...) return ... with Pre => Acc in Global_Access; In this case, if the object designated by Acc isn't defined globally, the precondition will fail, so you can safely assign Acc to an object of Global_Access in the body of Something. But, of course, that exposes part of your implementation in the precondition, so it's not clear that's a good thing. Randy.