comp.lang.ada
 help / color / mirror / Atom feed
From: wemagor@sym1.cca.rockwell.com_nospam (Wayne Magor)
Subject: Re: help with pointerproblem.
Date: 1998/09/11
Date: 1998-09-11T00:00:00+00:00	[thread overview]
Message-ID: <6ta4lf$e0b1@onews.collins.rockwell.com> (raw)
In-Reply-To: 35f88e65.0@news.pacifier.com


"Steve Doiel" <steved@pacifier.com> writes:

>Roger Carlsson wrote in message <35f7f673.0@newsfeed.uu.se>...
>>Hello.
>>
>>I'm writing a program in ada95 with opengl on W95.
>>
>>I have the following definitions in GL.ads:
>>
>>type GLubyte     is new C.unsigned_char;
>>type GLpointer   is access all GLubyte;  -- our substitute for "void *"
>>
>>and
>>
>>procedure (.......; x : GLpointer);
>>
>>
>>My own types:
>>
>>type VertexArray is array (NATURAL range <>) of aliased GLfloat;
>>type VertexArrayPtr is access VertexArray;
>>
>>
>>and in the program:
>>VPtr : VertexArrayPtr;
>>.....
>>
>>VPtr := new VertexArray(0 .. n);
>>
>>
>>procedure(....., GLpointer(VPtr));
>>
>>I want to give the procedure my VertexArray as argument x.
>>My question is: How do i convert my VertexarrayPtr to a GLpointer?
>>I have tried different solutions but the compiler complains like:
>>Target designated type not compatible with type VertexArray.
>>
>>If i can not. Can i rewrite my own types so it works?
>>The VertexArray must hold GLfloat's.
>>
>
>
>You could give the following a shot.
>
>with System.Address_To_Access_Conversions;
>.
>.
>package ToGlPointerPackage is new
>  System.Address_To_Access_Conversions( GLUbyte );
>
>function ToGLpointer( vPtr : VertexArrayPtr) return GLPointer IS
>begin
>  return GLPointer( ToGlPointerPackage.To_Pointer( vPtr.ALL'ADDRESS ) );
>end ToGLpointer;
>
>I'm not sure about correctness, but it makes the compiler happy.


Since VertexArray is unconstrained, there will have to be a descriptor
someplace.  It's likely the pointer points to the descriptor instead
of the data.  I'd prefer to take the 'address of element zero of the
array.  Seems to me that's more likely to work across nearly all
platforms.  Like this:

  return GLPointer (ToGlPointerPackage.To_Pointer (vPtr(0)'Address));


Wayne.




  reply	other threads:[~1998-09-11  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-09-10  0:00 help with pointerproblem Roger Carlsson
1998-09-10  0:00 ` Steve Doiel
1998-09-11  0:00   ` Wayne Magor [this message]
1998-09-11  0:00     ` Mats Weber
1998-09-12  0:00     ` dewarr
1998-09-17  0:00       ` Matthew Heaney
1998-09-11  0:00 ` Mats Weber
replies disabled

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