ISO C forbids casting between void* and any function pointer, since it assumes (for portabilities sake), they can have different widths.
Therefore, compilers will spit out an ugly warning for code casting the result of dlsym to a function pointer.
The standard way of solving this is to replace the simple cast to function pointer, with a rather clumsy cast like this:
/* before: */
if (!res)
res = (GL3WglProc) dlsym(libgl, proc);
/* after: */
if (!res)
*(void **)(&res) = dlsym(libgl, proc);
Looks dangerous, but confirms to both ISO C and POSIX. Since POSIX.1-2013 every confirming implementation has to support casting between void* and function pointers. Nevertheless, most compilers still spit out a warning.
I've done this on my local fork, and can confirm it's working if compiled as C. No clue how a C++ compiler will react to this, though.
ISO C forbids casting between
void*
and any function pointer, since it assumes (for portabilities sake), they can have different widths. Therefore, compilers will spit out an ugly warning for code casting the result ofdlsym
to a function pointer.The standard way of solving this is to replace the simple cast to function pointer, with a rather clumsy cast like this:
Looks dangerous, but confirms to both ISO C and POSIX. Since POSIX.1-2013 every confirming implementation has to support casting between
void*
and function pointers. Nevertheless, most compilers still spit out a warning.I've done this on my local fork, and can confirm it's working if compiled as C. No clue how a C++ compiler will react to this, though.