Search code examples
c++constantssignature

Meaning of two const in C/C++ signature


I've been wrapping a gl file for scheme and it failed twice in the gl.h header. I'm on OSx so it might be platform dependent, but I never seen this syntax anywhere else in my life.

typedef void (* glMultiDrawElementsProcPtr) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount);

Notice the const GLvoid* const *indices. The scheme C interpreter has a small C subset and doesn't understand this part of the header.

What does it mean and how can I safely replace it by something else... I changed it to

const GLvoid** indices


Solution

  • Types in C and C++ are read from right to left except that most people insist in placing the const on the wrong side. Once you fixed the const placement from

    const GLvoid* const*
    

    to

    GLvoid const* const*
    

    it becomes trivial to read the type: It is a pointer to a const pointer to a const object of type GLvoid (you probably can't really have ovjects of type GLvoid but it's the placeholder for any object). You can also have the combinations where the inner pointer is modifiable and/or the object is modifiable depending on which const you leave out.