3

I am reading the OpenGL Super Bible 7th edition and in one of the earliest chapters there is an example of shader source code written like this:

static const GLchar * vertex_shader_source[] =
{
"#version 450 core                  \n"
"                                   \n"
"void main(void)                    \n"
// ... etc ...
};

Why is this code stored in an GLchar pointer source array variable?

I mean, isn't GLchar* alone enough to store a certain number of consecutive bytes? i.e. why not:

static const GLchar* source = ...

or:

static const GLchar source[] = ...

Why do we have to use both * and []?

I understand static const, so that's not a problem BTW.

Paweł Pela
  • 421
  • 3
  • 16
  • 1
    because you are initializing the array at the same time with the part between { ... }, so you want compiler to know its an array – michnovka Oct 21 '16 at 00:45
  • 1
    An array of one item that is a pointer, is effectively the same as that pointer. You can detect the difference via `decltype` but such sophistication doesn't seem relevant here. Possibly this array is a convention that supports having more than one pointer in the array. – Cheers and hth. - Alf Oct 21 '16 at 00:45
  • 1
    There may be multiple vertex shaders in this array, simple as that. – hidefromkgb Oct 21 '16 at 00:46

0 Answers0