mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 10:09:43 +01:00
Silence GCC warnings about void*
-to-function-pointer casts
GCC warns on casting `void*` to function pointers. This is because the C standard makes a clear distinction between pointers to objects (`void*`) and pointers to functions (function pointers), and does not specify anything related to being able to cast object pointers to function pointers. The warning message is factually wrong, though - it states that it is forbidden by ISO C, when in fact it is not, and is actually just unspecified. We can't get rid of the cast entirely, because we need the explicit cast (the C standard _does_ mandate you need an explicit cast when converting between object pointers and function pointers), and at the end of the day, this is simply how `SDL_LoadFunction()` works (and more importantly, how `dlsym()` works), so we can't get rid of it, and we have no reason to anyways since it means we don't have a hard runtime dependency on Steam (unlike some other games) and casting `void*` to function pointers always behaves well on every single platform we ship on that supports Steam. Unfortunately, this warning seems to be a part of -Wpedantic, and there's no way to disable this warning specifically without disabling -Wpedantic. Luckily, I've found a workaround - just cast to `intptr_t` before casting to the function pointer. Hopefully the compiler doesn't get smarter in the future and this ends up breaking or anything...
This commit is contained in:
parent
f3786a8e3f
commit
58c518c856
1 changed files with 1 additions and 1 deletions
|
@ -86,7 +86,7 @@ int32_t STEAM_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FOREACH_FUNC(rettype, name, params) \
|
#define FOREACH_FUNC(rettype, name, params) \
|
||||||
name = (rettype (*) params) SDL_LoadFunction(libHandle, #name); \
|
name = (rettype (*) params) (intptr_t) SDL_LoadFunction(libHandle, #name); \
|
||||||
if (!name) \
|
if (!name) \
|
||||||
{ \
|
{ \
|
||||||
vlog_error(STEAM_LIBRARY " symbol " #name " not found!"); \
|
vlog_error(STEAM_LIBRARY " symbol " #name " not found!"); \
|
||||||
|
|
Loading…
Reference in a new issue