Pointer Arguments to OpenGL Funtions

Started by
2 comments, last by Tom Backton 14 years, 2 months ago
I've been reading OpenGL 3.2's specification and I noticed that pointer arguments to some functions, for example glMultiDrawArrays, are not pointers-to-const while data is not written through them. I opened the gl3.h file available at opengl.org and indeed in some functions these pointers are not const. As a result, I can't pass pointers to const arrays to these functions without C-style explicit type-casting or const_cast<>(). Is it possible/safe to edit the gl3.h file (make those pointers const) or I'll just have to use type-casting? And why are these pointers not const in the first place, if there are no writes through the pointers?
Advertisement
const_cast may be evil, but editing 3rd party API headers is just diabolical.

[edit] Remember that GL is a C API, not a C++ API -- Perhaps they don't use const because it is a relatively new addition to the C language (it was borrowed from C++), and they want to be compatible with all C compilers?

[Edited by - Hodgman on February 13, 2010 6:53:07 AM]
I don't think so because some pointers, like const void* pointer in glMultiDrawArrays and all other VA functions, does use the const qualifier, while other for-reading-only pointer arguments don't use const. Also, in other functions, like glMultiDrawElements, pointers ARE const, but if I'm not mistaken it doesn't appear in the spec (in which they aren't const), only in the downloadable gl3.h. While the const void* pointer is const in the spec too. I don't understand why...if the implementation perfectly follows the spec and doesn't write through the pointers then editing the header and using const_cast are both practically safe, but they are still theoretically not type-safe...So what should I do? And why aren't these pointers const if nothing is written through them?
...

Am I the only one who wants to pass pointers-to-const to vertex-array drawing functions?

This topic is closed to new replies.

Advertisement