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,74166d5f7afa0c82 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!nntp.megapath.net!news.megapath.net.POSTED!not-for-mail NNTP-Posting-Date: Fri, 31 Dec 2004 15:30:53 -0600 From: "Randy Brukardt" Newsgroups: comp.lang.ada References: Subject: Re: Return_By_Reference or Return_By_Copy (GNAT bug?) Date: Fri, 31 Dec 2004 15:32:31 -0600 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 Message-ID: NNTP-Posting-Host: 64.32.209.38 X-Trace: sv3-qT5UTmgO5n+vM9UgkwPAr5AXtr2ec93aUnUNF2GGCOj5ZAZrDrLd6Lg4rWOI6D30keBtNAkpqAxhuvn!3UuUYDGKsKk2G6njPtKT9LvXLdva62ymIFUaQDWdnkqrPI7/z4mk0oyrOovpMy8wkeUIweBsLwtF X-Complaints-To: abuse@megapath.net X-DMCA-Complaints-To: abuse@megapath.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.22 Xref: g2news1.google.com comp.lang.ada:7360 Date: 2004-12-31T15:32:31-06:00 List-Id: "Duncan Sands" wrote in message news:mailman.19.1104491242.527.comp.lang.ada@ada-france.org... > Consider the following version of the Rosen trick. Should > A_Type be returned by reference or by copy? GNAT 3.15p says: > by reference; more recent versions of GNAT say: by copy. My > understanding is that it should be by reference, because it > has a component R_Type that is a return_by_reference type > (R_Type is return_by_reference because the full view is limited > private). A_Type certainly is return-by-reference. But take care: Ada 2005 flushes the entire return-by-reference garbage in favor of build-in-place limited functions. Such functions only can return aggregates or build-in-place functions (or be built component-by-component in an extended return statement). To do what you want in Ada 2005 would require using an anonymous access function: function Get_an_A return access A_Type; Note that this makes the reference return explicit (no magical rules to page through). This probably is the biggest incompatibility in Ada 2005 (although it often is just changing a runtime check to compile-time). We tried various halfway solutions, but eventually decided that this was so screwed up that we were better off just doing it over correctly. (Build-in-place functions can be used to initialize objects, so we now can write meaningful limited constants, and don't have to stand on our heads to initialize things.) Moral: Avoid functions returning limited types in Ada 95 code, since they'll likely have to be changed in Ada 2005 anyway. Randy.