Generic (void *)int

Mark Raynsford org.openjdk at io7m.com
Mon Feb 18 11:45:53 UTC 2019


On 2019-02-18T11:24:51 +0000
Maurizio Cimadamore <maurizio.cimadamore at oracle.com> wrote:
>
> While an API can be added for this, we must also thread carefully - 
> there's a balance here between allowing common C idioms and safety - if 
> we make it too easy to create pointers to 'random' addresses, we also 
> make it easy for people to shoot themselves in the foot.

I think it's very rare to see an API that actually *requires* this kind
of unpleasantness. 

For the morbidly curious, this API is down to the "backwards
compatibility" approach used in the oldest parts of the OpenGL API.
Essentially, they appeared to want to use the same functions to refer
to both arrays of vertex data allocated on the CPU, and arrays of
vertex data allocated on the GPU. If no GPU-based array is currently
active, then the last parameter of glVertexPointer is interpreted as a
CPU-side memory address. If a GPU-based array *is* active, the last
parameter is interpreted as a relative offset from the start of the
array on the GPU. It's fairly gross, as you can see! I can't think of
any other API that works this way. Most OpenGL bindings such as JOGL and
LWJGL actually expose both pointer-typed and a long-typed overloads of
glVertexAttribPointer and friends for this reason. Maybe something more
along those lines would be satisfactory for these edge cases?

-- 
Mark Raynsford | http://www.io7m.com



More information about the panama-dev mailing list