From 58c518c856faedb8ea18bd1ddb0404cf21c00ae6 Mon Sep 17 00:00:00 2001 From: Misa Date: Thu, 21 Oct 2021 01:00:06 -0700 Subject: [PATCH] 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... --- desktop_version/src/SteamNetwork.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desktop_version/src/SteamNetwork.c b/desktop_version/src/SteamNetwork.c index 11511db9..214f03f6 100644 --- a/desktop_version/src/SteamNetwork.c +++ b/desktop_version/src/SteamNetwork.c @@ -86,7 +86,7 @@ int32_t STEAM_init(void) } #define FOREACH_FUNC(rettype, name, params) \ - name = (rettype (*) params) SDL_LoadFunction(libHandle, #name); \ + name = (rettype (*) params) (intptr_t) SDL_LoadFunction(libHandle, #name); \ if (!name) \ { \ vlog_error(STEAM_LIBRARY " symbol " #name " not found!"); \