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,68536605ede13a20 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.190.71 with SMTP id go7mr7098274pbc.8.1324537892021; Wed, 21 Dec 2011 23:11:32 -0800 (PST) Path: lh20ni50765pbb.0!nntp.google.com!news1.google.com!postnews.google.com!h11g2000yqd.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: GNAT - return by anonymous access Date: Wed, 21 Dec 2011 23:11:31 -0800 (PST) Organization: http://groups.google.com Message-ID: <6e5ee357-7409-4974-917c-d7236c782d31@h11g2000yqd.googlegroups.com> References: <784c67eb-a542-41b0-b23d-fca1234e56b2@n10g2000vbg.googlegroups.com> <95f3b0fc-af24-4ace-afc9-227e8893ea99@n6g2000vbg.googlegroups.com> <91845790-2447-4b2c-a6b5-1a52557c8c17@d10g2000vbk.googlegroups.com> <4f78ef9f-ca8d-43ef-ab71-0f775fbeebd9@z19g2000vbe.googlegroups.com> NNTP-Posting-Host: 207.200.116.71 Mime-Version: 1.0 X-Trace: posting.google.com 1324537891 22505 127.0.0.1 (22 Dec 2011 07:11:31 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 22 Dec 2011 07:11:31 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: h11g2000yqd.googlegroups.com; posting-host=207.200.116.71; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-Via: HTTP/1.1 (Velocity/3.1.2.1 [uScMs f p eN:t cCMp s ]), HTTP/1.1 spider-ntc-ta03.proxy.aol.com[CFC87003] (Prism/1.2.1), HTTP/1.1 cache-ntc-ab07.proxy.aol.com[CFC87447] (Traffic-Server/6.1.5 [uScM]) X-Google-Web-Client: true X-Google-Header-Order: ARLUECVH X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.5; AOLBuild 4337.5401; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; HPDTDF; BRI/1; .NET4.0C; BRI/2; AskTbARS/5.12.2.16749),gzip(gfe) Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2011-12-21T23:11:31-08:00 List-Id: On Dec 21, 4:33=A0pm, Simon Belmont wrote: > On Dec 21, 2:29=A0am, AdaMagica wrote: > > > Hm, no, return-by-reference has been replaced by build-in-place. > > Building in place creates another object, does it not? =A0Changes to a > returned built in place type would not affect the original object. > Suppose I have a package with some internal object of a limited, not > necessarily allocated, but that has to get exposed to other units: > > package body Sample is > > =A0 foo : Lim_Type_Ptr :=3D -- ...stuff > > =A0 function Get return Lim_Type is > =A0 begin > =A0 =A0 return foo.all; > =A0 end Sample; > > The above code, which as I understand it would be legal Ada95 code, > doesn't return the actual object, but returns a pointer that the > compiler automatically dereferences behind the scenes. =A0The client > can't change, copy, or delete the object or the access value because > it cannot reference it. > > In the Ada05 version, it would have to return a Lim_Type_Ptr (or, > equivilently, an access Lim_Type), and the client would have to > dereference it. =A0Now the client has free means to change, copy, and > deallocate the access value. =A0At best it works the same, and at worst > an errant programmer can wreak havoc. I think this could be solved by declaring a private type (limited private, if you prefer) to represent an "access" or "handle" or "reference" to test_type. It would be implemented as an access type, basically, but the client wouldn't see it as an access type, so it couldn't deallocate it, and if you make it limited private it couldn't copy it either. The only thing you lose is that since it's private, you couldn't directly use it to access components of the accessed type (test_type). But in your example, test_type is private anyway, so this isn't much of a loss, except for the ability to access the discriminant p_obj, and you could provide a function to do that. > I suppose my question is why? =A0No one seems to have a valid technical > reason for this change, other than returning-by-reference is > 'unusual', which doesn't seem like nearly enough of a good reason to > take something that was working fine and make it more dangerous. You might want to check out http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ais/ai-10318.txt?rev=3D1.16 just to convince yourself that, yes, they *did* have plenty of valid technical reasons. Even if this is hard to follow, at least the fact that they had as much discussion as they did should make it clear that this wasn't something the ARG did just because they got drunk and felt like changing something. -- Adam