I'm using glad to generate OpenGL bindings, and have generated a debug build which includes the following:
// this symbol only exists if generated with the c-debug generator
#define GLAD_DEBUG
typedef void (* GLADcallback)(const char *name, void *funcptr, int len_args, ...);
/*
* Sets a callback which will be called before every function call
* to a function loaded by glad.
*
*/
GLAPI void glad_set_pre_callback(GLADcallback cb);
/*
* Sets a callback which will be called after every function call
* to a function loaded by glad.
*
*/
GLAPI void glad_set_post_callback(GLADcallback cb);
The documentation gave an example how to define this callback, which looks like this:
void _post_call_callback_default(const char *name, void *funcptr, int len_args, ...) {
GLenum error_code;
error_code = glad_glGetError();
if (error_code != GL_NO_ERROR) {
fprintf(stderr, "ERROR %d in %s\n", error_code, name);
}
}
What I don't understand is how I'm supposed to access the varargs. I'm guessing that they are the values that are passed to the OpenGL function, and thus can be any type. However, I must specify the type to va_arg in order to access the values.
I feel that the parameter len_args
is hinting that there is some way to iterate over the varargs, but I don't understand how it's supposed to be used without knowing the types. How are they meant to be used?