2

I am writing a cross-platform OpenGL function loading library. On Windows, the compiler (oddly enough, both VS and GCC) seems fine with implicitly converting one kind of function pointer (the return type from wglGetProcAddress being a void(*)()) into another type of function pointer.

GCC on Linux however is not. glXGetProcAddress will return a void(*)(), but it will always issue a warning about it. And since OpenGL has literally thousands of these things, it adds up to a giant diagnostic spew that's entirely irrelevant.

Is there some way to disable this particular warning? Either with a #pragma or some way of rearranging the code so GCC shuts up? I tried the whole #pragma diagnostic ignore -Wblahblah, but I couldn't find a "blahblah" that matched the warning I was getting.

2
  • As a side note, you may want to check out glew.sourceforge.net to deal with loading all of those Commented Oct 24, 2012 at 17:44
  • 1
    @hexist: Yeah, I'm trying to replace GLEW, not use it. Commented Oct 24, 2012 at 17:48

1 Answer 1

3

I'm pretty sure you're supposed to use the provided macros to get the correct types out. For example, taken from the gl3w OpenGL extension loader (you have to run the python script to get it to generate code like this), it has lines that look like:

gl3wBindImageTexture = (PFNGLBINDIMAGETEXTUREPROC)get_proc("glBindImageTexture");

That weird PFNGLBINDIMAGETEXTUREPROC in the middle is a macro for the correct function type of the glBindImageTexture function (you can see its name is actually Pointer FunctioN GLBINDIMAGETEXTURE PROC).

Sign up to request clarification or add additional context in comments.

2 Comments

I'm not a C programmer by trade, but I was told by C programmers that doing unnecessary explicit casts was bad in C. That you should let the implicit cast system handle it.
@Nicol: I'm not sure where you learned that. In C, you should generally avoid explicitly casting void* to other pointer types (such as the return value of malloc), since there is an implicit cast from void* to any other data pointer type. However, function pointers are entirely different beasts -- there is no implicit function pointer casting, so you should explicitly cast when you need to (which shouldn't be too often, but this looks like a good case here).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.