Skip to content

Commit 2cd155f

Browse files
committed
Fix funciton pointer cast warning win backend
Fix function pointer cast warning when compiling windows backend with strict compiler settings.
1 parent f4c77eb commit 2cd155f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

windows/hid.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,13 @@ static int lookup_functions()
138138
goto err;
139139
}
140140

141-
#if defined(__GNUC__)
142-
# pragma GCC diagnostic push
143-
# pragma GCC diagnostic ignored "-Wcast-function-type"
144-
#endif
145-
#define RESOLVE(lib_handle, x) x = (x##_)GetProcAddress(lib_handle, #x); if (!x) goto err;
141+
/* Avoid direct function-pointer cast from FARPROC to typed callback pointer.
142+
Using memcpy keeps this warning-free regardless of the compiler and compiler settings. */
143+
#define RESOLVE(lib_handle, x) do { \
144+
FARPROC proc_addr = GetProcAddress(lib_handle, #x); \
145+
if (!proc_addr) goto err; \
146+
memcpy(&x, &proc_addr, sizeof(x)); \
147+
} while (0)
146148

147149
RESOLVE(hid_lib_handle, HidD_GetHidGuid);
148150
RESOLVE(hid_lib_handle, HidD_GetAttributes);
@@ -167,9 +169,6 @@ static int lookup_functions()
167169
RESOLVE(cfgmgr32_lib_handle, CM_Get_Device_Interface_ListW);
168170

169171
#undef RESOLVE
170-
#if defined(__GNUC__)
171-
# pragma GCC diagnostic pop
172-
#endif
173172

174173
return 0;
175174

0 commit comments

Comments
 (0)