This function syntax is confusing me gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)

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.
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.