* help with pointerproblem. @ 1998-09-10 0:00 Roger Carlsson 1998-09-10 0:00 ` Steve Doiel 1998-09-11 0:00 ` Mats Weber 0 siblings, 2 replies; 7+ messages in thread From: Roger Carlsson @ 1998-09-10 0:00 UTC (permalink / raw) 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. Thank You. Roger. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: help with pointerproblem. 1998-09-10 0:00 help with pointerproblem Roger Carlsson @ 1998-09-10 0:00 ` Steve Doiel 1998-09-11 0:00 ` Wayne Magor 1998-09-11 0:00 ` Mats Weber 1 sibling, 1 reply; 7+ messages in thread From: Steve Doiel @ 1998-09-10 0:00 UTC (permalink / raw) 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. I hope this helps, SteveD ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: help with pointerproblem. 1998-09-10 0:00 ` Steve Doiel @ 1998-09-11 0:00 ` Wayne Magor 1998-09-11 0:00 ` Mats Weber 1998-09-12 0:00 ` dewarr 0 siblings, 2 replies; 7+ messages in thread From: Wayne Magor @ 1998-09-11 0:00 UTC (permalink / raw) "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. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: help with pointerproblem. 1998-09-11 0:00 ` Wayne Magor @ 1998-09-11 0:00 ` Mats Weber 1998-09-12 0:00 ` dewarr 1 sibling, 0 replies; 7+ messages in thread From: Mats Weber @ 1998-09-11 0:00 UTC (permalink / raw) Wayne Magor wrote: > 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)); This (taking the address of the first element instead of the address of the array) is a hack that is not necessary anymore with Ada 95, because the RM now says it has to be the same. return GLPointer (ToGlPointerPackage.To_Pointer (vPtr'Address)); is just fine. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: help with pointerproblem. 1998-09-11 0:00 ` Wayne Magor 1998-09-11 0:00 ` Mats Weber @ 1998-09-12 0:00 ` dewarr 1998-09-17 0:00 ` Matthew Heaney 1 sibling, 1 reply; 7+ messages in thread From: dewarr @ 1998-09-12 0:00 UTC (permalink / raw) In article <6ta4lf$e0b1@onews.collins.rockwell.com>, No@Junk.Mail wrote: > > 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)); > This is incorrect, it is in fact rather unlikely that the pointer points to the descriptor. The two more common ways of implementing unconstrained pointers are as follows: 1. Fat pointers, as used by GNAT by default. Here the pointer is two pointers, one to the data and one to the descriptor. 2. Thin pointers, as used by GNAT if a size clause is used to force single pointer length. Here the pointer is to the data, but the bounds are just "behind" the data. Many other Ada compilers have used this technique. It is actually quite rare to point to a descriptor (I think that the RR compiler may have done this at least at one point). Even if the pointer *does* point to the descriptor, you still should expect that arr'address is the address of the first element on an Ada 95 compiler because of RM 13.3(14): For an array X, X'Address should point at the first component of the array, and not at the array bounds. This is implementation advice rather than a requirement, but a compiler is supposed to follow implementation advice unless there is a good reason not to, and it is hard to imagine that this obviously good advice would not be followed. Moreover, if your compiler does not follow it, then this MUST be documented, this is a requirement of annex M. If you have an Ada 95 compiler which does not follow this implementation advice, I would report it as a bug to your vendor. Nevertheless, the caution of using the address of the first element is a reasonably one, which might possibly help you out with a recalcitrant vendor who for some reason refused to follow this implementation advice. Most certainly GNAT DOES follow this advice, and every other Ada 95 compiler which I am aware of also follows this advice. Robert Dewar Ada Core Technologies -----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: help with pointerproblem. 1998-09-12 0:00 ` dewarr @ 1998-09-17 0:00 ` Matthew Heaney 0 siblings, 0 replies; 7+ messages in thread From: Matthew Heaney @ 1998-09-17 0:00 UTC (permalink / raw) dewarr@my-dejanews.com writes: > It is actually quite rare to point to a descriptor (I think > that the RR compiler may have done this at least at one > point). Access objects designating unconstrained arrays in the VMS Ada compiler (circa 1990) pointed to the descriptor, which pointed to the array itself. To get around this, bindings would be written to point to a large constrained array, as in: type Character_Array is array (Natural range 0 .. 1_000_000) of Character; type String is access Character_Array; for String'Storage_Size use 0; Obviously, you don't ever designate an actual array of that size, but the representation of the access type matches that of the C code on the other side. It's up to the programmer to find the real end of the array (usually by searching for the null character, or for whatever value designates the end-of-array). The SUN compiler I'm using now implements unconstrained array access types using the thin pointer technique. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: help with pointerproblem. 1998-09-10 0:00 help with pointerproblem Roger Carlsson 1998-09-10 0:00 ` Steve Doiel @ 1998-09-11 0:00 ` Mats Weber 1 sibling, 0 replies; 7+ messages in thread From: Mats Weber @ 1998-09-11 0:00 UTC (permalink / raw) Roger Carlsson wrote: > 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 *" The substibute for void * in Ada is called System.Address. Just write your C subporgrams in Ada with System.Address as parameters, e.g: function example (X : System.Address) return Interfaces.C.Int; pragma Import (C, example); ... Z : VertexArray(...); Result := example(Z'Address); I have always done it this way and it works great will all compilers I have used. Another approach is using access parameters (you get better type checking this way) but I'll let someone else decribe that (I have never used it myself). ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~1998-09-17 0:00 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 1998-09-10 0:00 help with pointerproblem Roger Carlsson 1998-09-10 0:00 ` Steve Doiel 1998-09-11 0:00 ` Wayne Magor 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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox