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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c08a7609345f4e5 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Path: g2news1.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Limited use for limited with? References: <853314bc-0f79-435f-86a5-d7bcdd610731@c10g2000yqh.googlegroups.com> <82y6ajg07m.fsf@stephe-leake.org> Date: Thu, 07 Oct 2010 07:55:45 -0400 Message-ID: <82ocb6ushq.fsf@stephe-leake.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (windows-nt) Cancel-Lock: sha1:3nm02w1xUaJDt2r0suL8DB+4mT4= MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: 2e79d4cadb53fe029e66118402 Xref: g2news1.google.com comp.lang.ada:14421 Date: 2010-10-07T07:55:45-04:00 List-Id: Adam Beneschan writes: > On Sep 30, 12:27 am, Stephen Leake > wrote: >> Ludovic Brenta writes: >> > I generally think twice or three times before declaring an access type >> > in the same package as the object type. In fact, I think twice before >> > declaring any access type at all :) To me, an access type makes the >> > package unclean. >> >> > Since, in Ada, all objects of tagged types are passed by reference and >> > since Ada has class-wide types, you do not need any access type to >> > achieve pass-by-reference semantics or dynamic dispatching. This >> > leaves dynamic memory allocation as the only remaining justification >> > for access types. >> >> You left out accessibility checks, which are an important reason for >> named access types. > > Really? Most uses of anonymous access types still involve > accessibility checks. Yes, and that's the point. > The main case where they don't is access parameters; and in that case, > you usually don't want accessibility checks unless you're going to > store the parameter somewhere where it could live after the subprogram > is completed, and doing so is going to involve an accessibility check > at the point where it's stored, whether or not the type of the stored > data is named or anonymous. Exactly. Suppose we have the following: type My_Type is record ... end record; type My_Access_Type is access all My_Type; procedure Foo_One (A : access My_Type); procedure Foo_Two (A : My_Access_Type); Inside Foo_Two, we know that the accessibility level of A is the same as the declaration of My_Access_Type, so you can save it to any value of that type; the accessibility check will pass (and should be removed by an optimizing compiler). Inside Foo_One, the accessibility level of A is likely the point of the call; it is not safe to save it, since you have no control over how the caller has declared the actual for A. So if you need to save copies of pointers, you need named access types, so you can know ahead of time that the accessibility check will not fail. In Ada 2012, it may be possible to use preconditions to enforce accessibility requirements; that would allow some more uses of anonymous access parameters. -- -- Stephe