How to portably use SDL_GL_GetProcAddress in C++?

In some C++ code I have lines like

glDrawTexsOES =

clang warns

Cast between pointer-to-function and pointer-to-object is an extension

The genesis of this warning is that SDL_GL_GetProcAddress is defined as returning void*, which is an object pointer. It seems it should be defined as returning a function pointer, i.e void (*fptr)(void). Until SDL is fixed, how can I use SDL_GL_GetProcAddress portably, i.e without the warning?

If you want to make the pedantic C++ compiler happy, I guess you could create a wrapper in C that does your proposed conversion. clang doesn’t throw a warning there, although it may invoke implementation-defined behavior. The specification text is too confusing for me.

/* wrapper.h */
typedef void (*voidfn)(void);
#ifdef __cplusplus
extern "C" {
	voidfn SDL_GL_GetProcAddress_CPP(const char * txt);
#ifdef __cplusplus
/* wrapper.c */
voidfn SDL_GL_GetProcAddress_CPP(const char * txt)
	return (voidfn)SDL_GL_GetProcAddress(txt);

Thank you for the suggestion. I thought about this way before but am hoping for a simpler way that doesn’t require wrapper files.

I filed bug 4131. Perhaps I’ll just fix that and use the updated SDL.

If you really want to compile with -Wpedantic you can do that to suppress the warning:

*(void**)(&glDrawTexsOES) = (PFNGLDRAWTEXSOESPROC)SDL_GL_GetProcAddress("glDrawTexsOES");

but it may give strict aliasing warning with other compiler,
or this:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
glDrawTexsOES = (PFNGLDRAWTEXSOESPROC)SDL_GL_GetProcAddress("glDrawTexsOES");
#pragma GCC diagnostic pop

All these things don’t really make the code more portable (and I think the code works on all platforms that SDL supports anyway), they just shut the warning up.

Just disable the warning.