comp.lang.ada
 help / color / mirror / Atom feed
From: Bill Findlay <yaldnif.w@blueyonder.co.uk>
Subject: Re: Question[s] about aliased extended return.
Date: Sat, 10 Nov 2012 10:59:31 +0000
Date: 2012-11-10T10:59:31+00:00	[thread overview]
Message-ID: <CCC3E413.20EF1%yaldnif.w@blueyonder.co.uk> (raw)
In-Reply-To: 3f8ba99f-015f-4567-8d31-6c711beb58c4@googlegroups.com

On 10/11/2012 01:52, in article
3f8ba99f-015f-4567-8d31-6c711beb58c4@googlegroups.com, "Shark8"
<onewingedshark@gmail.com> wrote:

> On Friday, November 9, 2012 6:08:46 PM UTC-7, Jeffrey Carter wrote:
>> On 11/09/2012 12:42 PM, Shark8 wrote:
>> 
>> The extended return exists for build-in-place results of limited types.
>> There's 
>> really no reason to use it for other types.
> 
> Really? I thought it was quite useful for initializing things too:
> 
> Type Matrix is Array(Positive Range <>, Positive Range <>) of Float;
> 
> Type Identity(Size: Positive) return Matrix is
> begin
>   Return Result : Matrix(1..size, 1..size):= (others => 0.0) do
>     For index in Matrix'Range(1) loop
>       Result(Index, Index):= 1.0;
>     end loop;
>   End return;
> end;
> 
> But I guess that's fairly related to build-in-place; the only difference being
> it's not limited.

I have not used it for a limited type yet; most of my use cases have been
like your example.  It is also nice for finalization after picking up the
value to be returned, e.g.:

   function pop
   return KDF9.word is
      pragma Assert(the_nest_depth > 0 or the_CPU_state = Director_state);
   begin
      return result : constant KDF9.word := the_nest(the_nest_depth - 1) do
         the_nest(the_nest_depth - 1) := 0;
         the_nest_depth := the_nest_depth - 1;
      end return;
   end pop;

-- 
Bill Findlay
with blueyonder.co.uk;
use  surname & forename;





      parent reply	other threads:[~2012-11-16  9:33 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-02 15:55 Question[s] about aliased extended return Shark8
2012-11-09  0:43 ` Randy Brukardt
2012-11-09  3:40   ` Yannick Duchêne (Hibou57)
2012-11-10  7:34     ` Randy Brukardt
2012-11-09 19:42   ` Shark8
2012-11-09 20:53     ` sbelmont700
2012-11-09 21:44       ` Yannick Duchêne (Hibou57)
2012-11-09 22:04         ` sbelmont700
2012-11-09 22:56           ` Shark8
2012-11-09 22:54         ` Shark8
2012-11-10  7:27           ` Randy Brukardt
2012-11-10 16:08             ` Shark8
2012-11-10  1:08     ` Jeffrey Carter
2012-11-10  1:52       ` Shark8
2012-11-10  2:17         ` Yannick Duchêne (Hibou57)
2012-11-10 10:59         ` Bill Findlay [this message]
replies disabled

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