comp.lang.ada
 help / color / mirror / Atom feed
From: "ldries46" <bertus.dries@planet.nl>
Subject: Re: acceess problem
Date: Mon, 25 Jul 2011 08:57:42 +0200
Date: 2011-07-25T08:57:42+02:00	[thread overview]
Message-ID: <4e2d13bc$0$2576$703f8584@news.kpn.nl> (raw)
In-Reply-To: <m2fwlvzj0a.fsf@pushface.org>

I have done what you suggested and got the following error message on the 
line
Axis1Amb : array (0 .. 3) of aliased GLfloat := (AxL, 0.0, 0.0, 1.0);

non-local pointer cannot point to local object

I agree that the bindings are not an example of beautifull ada programming 
but as far as I can see the biggest problem is that the OpenGL library is a 
rather old library with originally only C bindings. As you know C is not 
much more as a streamlined assembler language, where you do everything only 
for simplicity and no for readability.

L. Dries

"Simon Wright"  schreef in bericht news:m2fwlvzj0a.fsf@pushface.org...

"ldries46" <bertus.dries@planet.nl> writes:

> I am converting a C/C++ program with openGL to Ada and found the
> following problem:
>
> C/C++ code: float pAxis1Amb[] = { AxL, 0, 0, 1};
>                     glMaterialfv(vSide, GL_AMBIENT, pAxis1Amb);
> where         : GLAPI void APIENTRY glMaterialfv( GLenum face, GLenum
> pname, const GLfloat *params );
>
> In the Ada bindings the routine is declared as:
>                     procedure glMaterialfv (face   : GLenum; pname  :
> GLenum; params : GLfloatPtr);
> where :         type GLfloatPtr is access all GLfloat;
> and     :         subtype GLfloat is Float;
> I have created the following declarations : Axis1Amb   : array(0..3)
> of GLfloat := ( AxL, 0.0, 0.0, 1.0);
> 
> pAxis1Amb
> : GLfloatPtr := Axis1Amb'Access;
> Now I get the following error message : prefix of "Access" attribute
> must be aliased
> I have to follow the C/C++ code as close as possible.
> What do I do wrong?

That managed to get formatted _really_ strangely!

You could write

   Axis1Amb : array (0 .. 3) of aliased GLfloat := (AxL, 0.0, 0.0, 1.0);

and then

   pAxis1Amb : GLfloatPtr := Axis1Amb (0)'Access;

I guess you're going to pass pAxisAmb to glMaterialfv()? you will
probably get away with this, since a pointer to the first element is
very likely to be a pointer to the array. It might help to tie things
down to add

  pragma Convention (C, Axis1Amb);

I must say, this is a pretty low-quality binding! There appear to be 5
cases of 'pname' where 'params' is a 4-element array, one case where
it's a 3-element array, and one where a single value is required.

Actually IMO it's a low-quality C spec, too; a case of control coupling. 




  reply	other threads:[~2011-07-25  6:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-24 15:59 acceess problem ldries46
2011-07-24 17:27 ` Simon Wright
2011-07-25  6:57   ` ldries46 [this message]
2011-07-25  8:27     ` Simon Wright
2011-07-25  9:59       ` ldries46
2011-07-26 15:57       ` Gautier write-only
2011-07-26 17:43         ` Adam Beneschan
2011-07-27 12:06           ` Gautier write-only
2011-07-25  9:08     ` AdaMagica
replies disabled

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