From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-3.2 required=3.0 tests=BAYES_00,NICE_REPLY_A, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Equivalence between named access and anonymous access. Date: Wed, 6 Sep 2023 17:54:42 +0200 Organization: A noiseless patient Spider Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 6 Sep 2023 15:54:41 -0000 (UTC) Injection-Info: dont-email.me; posting-host="45219ce80d83fc0bae96dda1999b3d4d"; logging-data="2701186"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19jrDjgP2Se7fbqmpcm8wEF1QkHdfBA9xM=" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Cancel-Lock: sha1:R5TU5Yx31LTivCz/p6P0g/Gu7dk= Content-Language: en-US In-Reply-To: Xref: news.eternal-september.org comp.lang.ada:65605 List-Id: On 2023-09-06 16:37, Blady wrote: > I'm wondering about named access and anonymous access. > In the following Ada code, are the writing of parameter P1 type of > procedures PA and PB equivalent ? > > package C1 is >   type Inst is tagged null record; >   type Class is access all Inst'Class; > end C1; > > with C1; > package C2 is >   type Inst is tagged null record; >   type Class is access all Inst'Class; > >   procedure PA (Self : Inst; P1 : C1.Class); -- named access >   procedure PB (Self : Inst; P1 : access C1.Inst'Class); -- anonymous > access > end C2; > > Same with: >   function FA (Self : Inst) return C1.Class; -- named access >   function FB (Self : Inst) return access C1.Inst'Class; -- anonymous > access > > Are FA and FB writing equivalent? > If not why? They are not equivalent from the access checks point of view: declare Y : C2.Inst; X : aliased C1.Inst; begin C2.PA (Y, X'Access); -- Non-local pointer error C2.PB (Y, X'Access); -- Fine end; Furthermore, tagged anonymous access is controlling (dispatches) when not class-wide. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de