<p>The signature of <code>glfwGetProcAddress</code> is:</p>

<pre><code>GLFWglproc glfwGetProcAddress(const char *);
</code></pre>

<p>It's a function that takes a string and returns a <code>GLFWglproc</code>. which is defined as</p>

<pre><code>typedef void(* GLFWglproc) (void);
</code></pre>

<p>Essentially, that means <code>glfwGetProcAddress</code> is a function that takes a string and returns <strong>a pointer</strong> to function with no parameters and no return value.</p>

<hr>

<p><code>GLADloadproc</code> is a type alias defined as follows:</p>

<pre><code>typedef void* (* GLADloadproc)(const char *name);
</code></pre>

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

<hr>

<p>in the expression</p>

<pre><code>gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)
</code></pre>

<p>Inside, there is the expression</p>

<pre><code>(GLADloadproc)glfwGetProcAddress
</code></pre>

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

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

<p>This is all to end up passing it to <code>gladLoadGLLoader</code>, which expects a value of type <code>GLADloadproc</code>.</p>

<hr>

<p>TL;DR</p>

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

CC BY-SA 4.0
2019-02-26T20:14:55.530Z
Great answer. You look young, how are you so smart :P
Fare Osoba
CC BY-SA 4.0
2020-08-07T09:34:26.360Z
And the reason you pass this function pointer to the windowing system is so that the windowing system can use this "OpenGL extension loader mechanism" for loading functions...
jackw11111
CC BY-SA 4.0
2019-02-26T20:08:07.297Z
2019-02-26T20:08:07.297Z
Sebastián Mestre
<p>gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)</p>

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

CC BY-SA 4.0
2019-02-26T18:40:21.670Z
"*it has the brackets behind it*" Do you mean in front of it?
Nicol Bolas
CC BY-SA 4.0
2019-02-26T18:42:18.700Z
You are right. I have it reversed for some reason. Can youbtell me
Fare Osoba
CC BY-SA 4.0
2019-02-27T18:50:53.303Z
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
CC BY-SA 4.0
2019-02-27T18:56:50.197Z
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
<opengl><c++>
This function syntax is confusing me
Fare Osoba
# This function syntax is confusing me

(Asked by: username_0 on 2019-02-26)

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.

**Tags:** opengl, c++

> **Comments:**
> **username_1**: "*it has the brackets behind it*" Do you mean in front of it?  
> **username_0**: You are right. I have it reversed for some reason. Can youbtell me  
> **username_2**: 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.  
> **username_0**: I will delete it sorry. I didn't mean to piss anybody off, im just a newbie, the negative votes are a bit harsh :(  

---

## 1 answers

### Answer by username_3 on 2019-02-26. Score: 5 | Accepted answer

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

> **Comments:**
> **username_0**: Great answer. You look young, how are you so smart :P  
> **username_4**: And the reason you pass this function pointer to the windowing system is so that the windowing system can use this "OpenGL extension loader mechanism" for loading functions...  

---

