comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Return_By_Reference or Return_By_Copy (GNAT bug?)
Date: Fri, 31 Dec 2004 15:32:31 -0600
Date: 2004-12-31T15:32:31-06:00	[thread overview]
Message-ID: <lvKdndhnk8OQWEjcRVn-iw@megapath.net> (raw)
In-Reply-To: mailman.19.1104491242.527.comp.lang.ada@ada-france.org

"Duncan Sands" <baldrick@free.fr> 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.







  reply	other threads:[~2004-12-31 21:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-31 11:07 Return_By_Reference or Return_By_Copy (GNAT bug?) Duncan Sands
2004-12-31 21:32 ` Randy Brukardt [this message]
2005-01-01 22:00   ` Duncan Sands
2005-01-03 23:11     ` Randy Brukardt
2005-01-04  4:20       ` Larry Kilgallen
2005-01-04 23:27         ` Randy Brukardt
2005-01-08 13:06       ` Duncan Sands
2005-01-10 21:05         ` Randy Brukardt
2005-03-08 16:12           ` Duncan Sands
replies disabled

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