comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Question[s] about aliased extended return.
Date: Thu, 8 Nov 2012 18:43:15 -0600
Date: 2012-11-08T18:43:15-06:00	[thread overview]
Message-ID: <k7hjj5$kj9$1@munin.nbi.dk> (raw)
In-Reply-To: 9bbd99bd-f953-434d-b3c8-6e8a6d5c7dfd@googlegroups.com

"Shark8" <onewingedshark@gmail.com> wrote in message 
news:9bbd99bd-f953-434d-b3c8-6e8a6d5c7dfd@googlegroups.com...
>The syntax for the extended return given in the RM
>[ http://www.ada-auth.org/standards/12rm/html/RM-6-5.html ] allows for the 
>usage
> of the keyword ALIASED, with the restriction of "if the keyword aliased is 
> present
>  in an extended_return_object_declaration, the type of the extended return 
> object
>  shall be immutably limited."
>
>The 2012 rationale entry regarding the extended return
> [ http://www.ada-auth.org/standards/12rat/html/Rat12-4-6.html ] says of 
> immutably limited objects:
>* it is an explicitly limited record type,
>* it is a task type, protected type or synchronized interface,
>* it is a non-formal limited private type that is tagged or has an access 
>discriminant with a default expression, [or]
>* it is derived from an immutably limited type.
>
>(1) Doesn't this reduce the usefulness of the extended return?

No. Allowing "aliased" at all was a bug in Ada 2005; we preserved it only 
for compatibility (some GNAT customers used it a lot).

> There are a couple of times building the OpenGL binding where I would have 
> liked to do something like:
> Function some_vector( [params] ) Return Vector_of_points is
> begin
>  Return Result : access Vector_of_points( 1..size_from_params ) do
>    glFunctionPopulatingVector( glEnum_from_params, Result'access )
>  end return;
>end some_vector;
>in order to populate the vector with the requisite data, but this is not 
>allowed.

I presume you meant "aliased" rather than "access" in the return statement 
here.

IMHO, you get what you deserve when you use access parameters rather than 
"in out" parameters. There is no good reason to use an access parameter in a 
routine like Populating_Vector (at least in the Ada part - you might have to 
do all kinds of nasty things in the thin interface).

>(2) Is there a reason this is not allowed? (Thick/thin 'pointer' 
>differences?)

Of course. See the examples in AI05-0053-1. If a return object is a a 
temporary, allowing 'Access to be taken of it causes all kinds problems 
because its lifetime is unusual at best.

> Lastly, the GNAT compiler seems to reject the following, even though the 
> rationale says
> a "explicitly limited record type" qualifies as immutably limited:
>    Type LR is limited record
>      Data : Character:= 'X';
>    End record;
>
>    Function Get_LR Return LR is
>    begin
>        Return Result : aliased LR do
>           null;
>       end return;
>     end Get_LR;
>(3) Is this a bug, or am I just misreading everything?

Looks like a bug to me.

                                   Randy.





  reply	other threads:[~2012-11-16  8:53 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 [this message]
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
replies disabled

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