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=-2.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,74166d5f7afa0c82 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!proxad.net!usenet-fr.net!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Duncan Sands Newsgroups: comp.lang.ada Subject: Re: Return_By_Reference or Return_By_Copy (GNAT bug?) Date: Sat, 1 Jan 2005 23:00:56 +0100 Organization: Cuivre, Argent, Or Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1104616883 26891 212.85.156.195 (1 Jan 2005 22:01:23 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Sat, 1 Jan 2005 22:01:23 +0000 (UTC) Cc: Randy Brukardt To: comp.lang.ada@ada-france.org Return-Path: User-Agent: KMail/1.6.2 In-Reply-To: Content-Disposition: inline X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:7379 Date: 2005-01-01T23:00:56+01:00 Hi Randy, > A_Type certainly is return-by-reference. thanks for confirming. > function Get_an_A return access A_Type; > > Note that this makes the reference return explicit (no magical rules to page > through). I was playing around with return by reference to see if it is possible to get unserialized access to a protected variable using the Rosen trick (it is, see example below, especially the protected object P in package C). Will this be illegal in Ada 2005? All the best, Duncan. package B is type A_Type is limited private; function Get_The_A return A_Type; procedure Increment (An_A : A_Type); procedure Print (An_A : A_Type); private type R_Type (An_A : access A_Type) is limited null record; type A_Type is record R : R_Type (A_Type'Access); I : Integer := 0; end record; end; with Ada.Text_IO; use Ada.Text_IO; package body B is The_A : A_Type; function Get_The_A return A_Type is begin return The_A; end; procedure Increment (An_A : A_Type) is begin An_A.R.An_A.I := An_A.R.An_A.I + 1; end; procedure Print (An_A : A_Type) is begin Put_Line (An_A.I'Img); end; end; with B; use B; package C is protected P is function Get_A return A_Type; private P_A : A_Type; end P; end; package body C is protected body P is function Get_A return A_Type is begin return P_A; end Get_A; end P; end; with Ada.Text_IO; use Ada.Text_IO; with B; use B; with C; use C; procedure Y is procedure Look is The_A_Reference : A_Type renames P.Get_A; begin Print (The_A_Reference); Increment (The_A_Reference); Print (The_A_Reference); end; begin Put_Line ("Mechanism:" & Integer'Image (Get_The_A'Mechanism_Code)); New_Line; Look; New_Line; Look; end;