Home > Mobile >  What does "glfwSetErrorCallback" function returns?
What does "glfwSetErrorCallback" function returns?

Time:10-29

I'm learning GLFW 3.3, and, as it's said in functions description:

Returns the previously set callback, or NULL if no callback was set.

Source: [https://www.glfw.org/docs/3.3/group__init.html#gaff45816610d53f0b83656092a4034f40]

Now what I'm trying to do is to understand what kind of value it is. I tried to understand it as if the return value was a pointer to a function, because, as said about GLFWerrorfun type in the documentation:

typedef void(* GLFWerrorfun) (int, const char *) This is the function pointer type for error callbacks.

Source: [https://www.glfw.org/docs/3.3/group__init.html#ga6b8a2639706d5c409fc1287e8f55e928]

Here's my code:

#define GLFW_DLL
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>

void handleErrorCallback (int code, const char * description)
{
    // Code
}

int main (int argc, char * argv[])
{
    std::cout << glfwSetErrorCallback (handleErrorCallback) << std::endl;
    std::cout << glfwSetErrorCallback (NULL) << std::endl;

    return 0;
}

The first value written on the console is 0. I get it as the NULL was returned because no callback was set yet.

The second value written on the console is 1, and it confuses me: how did GLFWerrorfun return value was converted to an integer? All I see is that it's always returns '1' when the callback function was set and always '0' when it wasn't.

CodePudding user response:

glfwSetErrorCallback returns a pointer wich is interpreted as an integer.

I think this post will help:How to print function pointers with cout?

  • Related