# This function syntax is confusing me

I have never seen this syntax before. Presumably glfGetProcAddres is a function, but it has the brackets behind it. Is this only possible in open gl or is my c++ trash.

• "it has the brackets behind it" Do you mean in front of it? – Nicol Bolas Feb 26 at 18:40
• You are right. I have it reversed for some reason. Can youbtell me – Fare Osoba Feb 26 at 18:42
• I'm voting to close this question as off-topic because this is a fundamental question about the C++ programming language entirely unrelated to the problem of computer graphics. – Christian Rau Feb 27 at 18:50
• I will delete it sorry. I didn't mean to piss anybody off, im just a newbie, the negative votes are a bit harsh :( – Fare Osoba Feb 27 at 18:56

The signature of glfwGetProcAddress is:

GLFWglproc glfwGetProcAddress(const char *);


It's a function that takes a string and returns a GLFWglproc. which is defined as

typedef void(* GLFWglproc) (void);


Essentially, that means glfwGetProcAddress is a function that takes a string and returns a pointer to function with no parameters and no return value.

GLADloadproc is a type alias defined as follows:

typedef void* (* GLADloadproc)(const char *name);


Essentially, this means that this is the type of a function that takes a string and returns a void pointer (this is a type of pointer that can be safely converted to from every other type of pointer).

in the expression

gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)


Inside, there is the expression

(GLADloadproc)glfwGetProcAddress


Where we have a type in parenthesis followed by an identifier. This is known as a type cast, it means we are taking some value of some type and converting it to some other type.

In this case, we take our GLADloadproc function that takes string and returns pointer to function and we 'disguise' it as a function that takes string and returns void*. This works because we can convert any pointer to void*, even in function pointer return types.

This is all to end up passing it to gladLoadGLLoader, which expects a value of type GLADloadproc.

TL;DR

gladLoadGLLoader takes a GLADloadproc but we want to give it a GLFWglproc (*)(const char *). To be able to do this, we force the type system to take it anyways by using a type cast.

• Great answer. You look young, how are you so smart :P – Fare Osoba Feb 26 at 20:14