comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Question[s] about aliased extended return.
Date: Fri, 9 Nov 2012 11:42:37 -0800 (PST)
Date: 2012-11-09T11:42:37-08:00	[thread overview]
Message-ID: <bc5c504b-6261-4a18-a7b6-36bb95fabd7f@googlegroups.com> (raw)
In-Reply-To: <k7hjj5$kj9$1@munin.nbi.dk>

On Thursday, November 8, 2012 5:43:18 PM UTC-7, Randy Brukardt wrote:
> "Shark8" <onewingedshark@gmail.com> wrote in message 
> 
> > 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 : ALIASED 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.

Yes.

> 
> 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).

Ah that's kinda the point, this is WRT the implementation part [of my OpenGL binding] and therefore the interface between the thin/raw-imports and the more useful/friendly Ada world. (By Vector I mean something like "Array (Positive Range <>) of Float" [or whatever], not the Containers's Vector.)

As it is I have to do something like:
    Function Get_Elements(Item:Texture_Coordinate_Generation) Return Positive is
    begin
	case Item is
	when TEXTURE_GEN_MODE		=> Return 1;
	when OBJECT_PLANE | EYE_PLANE	=> Return 4;
	end case;
    end Get_Elements;

    Function GetTexGen (	coord : Texture_Coordinate_Type;
				pname : Texture_Coordinate_Generation)
				Return Double_Vector_Type is
    begin
	Return Result : Double_Vector_Type(1..Get_Elements( pname )) do
		glGetTexGendv(
			coord  => Convert(coord),
			pname  => Convert(pname),
			params => To_Pointer( Result'Address )
		);
	End Return;
    end GetTexGen;

Where Convert is Unchecked_Conversion to GLEnum, and To_Pointer is Address/access conversion. {Aliased return statements would then allow me to be rid of a whole dependency... oh well.}

> 
> > Lastly, the GNAT compiler seems to reject the following, [..] 
> >(3) Is this a bug, or am I just misreading everything?
> 
> Looks like a bug to me.

Thank you, good to know.



  parent reply	other threads:[~2012-11-09 19:42 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 [this message]
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