On Wednesday 31 July 2024 00:13:24 LIU Hao wrote:
> 在 2024-07-29 02:58, Pali Rohár 写道:
> > In file included from libsrc/wspiapi/WspiapiLoad.c:7:
> > libsrc/wspiapi/WspiapiLoad.c: In function ‘WspiapiLoad’:
> > mingw-w64-headers/include/wspiapi.h:50:20: warning: cast between 
> > incompatible function types from ‘void (__attribute__((stdcall)) *)(struct 
> > addrinfo *)’ to ‘int (__attribute__((stdcall)) *)()’ [-Wcast-function-type]
> >     { "freeaddrinfo",(FARPROC) WspiapiLegacyFreeAddrInfo } }
> >                      ^
> 
> These can be silenced by casting the pointer to an `INT_PTR` or `intptr_t` in 
> between.
> 
> Granted, I think this had better be special-case'd in GCC. Maybe it's just 
> too late?

It looks like that my gcc complain only about the incompatible return
type (void vs int). Casting between unspecified list of arguments () and
explicitly specified (const struct sockaddr *ptSocketAddress, ...) is
not a problem/warning.

So gcc complain only about WspiapiLegacyFreeAddrInfo which has void
return type. And not about WspiapiLegacyGetAddrInfo or
WspiapiLegacyGetNameInfo which have int return type (compatible with
DWORD, which is return type of FARPROC function type).

It looks like that casting whole function pointer to LPVOID type prior
casting to FARPROC mutes this warning.

Now I remember that in past I have already used casting return value
from GetProcAddress() to LPVOID and after that to the correct function
pointer type which muted gcc warnings.

Here is my change:

diff --git a/mingw-w64-headers/include/wspiapi.h 
b/mingw-w64-headers/include/wspiapi.h
index c95c46abcc54..19972a9030c7 100644
--- a/mingw-w64-headers/include/wspiapi.h
+++ b/mingw-w64-headers/include/wspiapi.h
@@ -47,7 +47,7 @@ extern "C" {
 
 #define WSPIAPI_FUNCTION_ARRAY { { "getaddrinfo",(FARPROC) 
WspiapiLegacyGetAddrInfo }, \
   { "getnameinfo",(FARPROC) WspiapiLegacyGetNameInfo }, \
-  { "freeaddrinfo",(FARPROC) WspiapiLegacyFreeAddrInfo } }
+  { "freeaddrinfo",(FARPROC) (LPVOID) WspiapiLegacyFreeAddrInfo } }
 
   char *WINAPI WspiapiStrdup (const char *pszString);
   WINBOOL WINAPI WspiapiParseV4Address (const char *pszAddress,PDWORD 
pdwAddress);



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to