comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Belmont <sbelmont700@gmail.com>
Subject: Re: GNAT - return by anonymous access
Date: Wed, 21 Dec 2011 16:33:04 -0800 (PST)
Date: 2011-12-21T16:33:04-08:00	[thread overview]
Message-ID: <4f78ef9f-ca8d-43ef-ab71-0f775fbeebd9@z19g2000vbe.googlegroups.com> (raw)
In-Reply-To: 91845790-2447-4b2c-a6b5-1a52557c8c17@d10g2000vbk.googlegroups.com

On Dec 21, 2:29 am, AdaMagica <christ-usch.gr...@t-online.de> wrote:
> Hm, no, return-by-reference has been replaced by build-in-place.

Building in place creates another object, does it not?  Changes 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

  foo : Lim_Type_Ptr := -- ...stuff

  function Get return Lim_Type is
  begin
    return foo.all;
  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.  The 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.  Now the client has free means to change, copy, and
deallocate the access value.  At best it works the same, and at worst
an errant programmer can wreak havoc.

I suppose my question is why?  No 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.

-sb




  parent reply	other threads:[~2011-12-22  0:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-17 19:17 GNAT - return by anonymous access Simon Belmont
2011-12-17 19:51 ` Simon Wright
2011-12-18  9:08 ` Georg Bauhaus
2011-12-19 23:46 ` Randy Brukardt
2011-12-20  0:14   ` Shark8
2011-12-20 23:18     ` Randy Brukardt
2011-12-21  0:44       ` Simon Belmont
2011-12-21  7:29         ` AdaMagica
2011-12-21 11:05           ` Georg Bauhaus
2011-12-21 11:43             ` AdaMagica
2011-12-21 12:05               ` Georg Bauhaus
2011-12-22  0:33                 ` Randy Brukardt
2011-12-22  0:33           ` Simon Belmont [this message]
2011-12-22  7:11             ` Adam Beneschan
2011-12-22 22:11               ` Simon Belmont
2011-12-23  0:56                 ` Randy Brukardt
2011-12-23 13:20                   ` Simon Belmont
2011-12-27 23:51                     ` Randy Brukardt
2011-12-20 23:53 ` anon
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox