+ 2
This parameter is confusing me
I'm learning opengl, and one of the parameters of the function glShaderSource() is: const GLchar* const* string The only thing I can understand from this expression is that neither the address pointed to by the pointer nor the value of the address can be changed (because there are 2 "const" expressions). But why are there 2 asterisks?
2 Answers
+ 1
what you need to know is that glShaderSource expects two related sequences which are the C-style arrays of values.
The #1 sequence is an array of C-strings, either zero-terminated or not and the #2 sequence is an array of integers, indicating the length of each of the strings in the first sequence. Note that the sequence is optional if the strings are Zero-terminated as the library will find the strings by itself.
---------------------------------------------------------------------------------------------------------
Let me try to simplify by tackling it in steps:
--------------------------------------------------------
#1 const GLchar is an immutable (constant) character.
#2 const GLchar * is a pointer to immutable GLchars, in this case your shader source.
#3 const GLchar * const is an immutable pointer to immutable GLchars, that means the pointer itself can not be changed to point somewhere else.
#4 const GLchar * const * is a pointer to an immutable pointer to immutable GLchars.
#5 string is the name of the parameter.
I don't know if it make a little sense now.
The GL-prefixed types are because the OpenGL specification needs to talk about types without tying itself into a particular language, so it introduces aliases of common C types.
0
Thanks for clarifying this concept for me!