On Wed, 18 Sep 2024, Jacek Caban wrote:

On 18.09.2024 14:06, Martin Storsjö wrote:
Modern GCC and Clang warn for these casts, with warnings like these:

../secapi/_chsize_s.c:20:6:
  warning: cast from 'FARPROC' (aka 'long long (*)()') to 'errno_t
((*))(int, long long) __attribute__((cdecl))' (aka 'int (*)(int, lo
ng long)') converts to incompatible function type
[-Wcast-function-type-mismatch]
    20 |         f = (errno_t __cdecl (*)(int, long long))
       |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    21 |             GetProcAddress (__mingw_get_msvcrt_handle (),
"_chsize_s");
       |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


That warning seems very impractical in code dealing with GetProcAddress. In Wine, we usually just cast it to (void *), but I recall that it was problematic for mingw-w64-crt for some reason too. Maybe we could just disable that warning in the configure script?

It's not strictly problematic to use regular (void*) casts, they also work the same. But some people raised that, in a strict language context, it isn't safe to cast function pointers to object pointers - even if it is ok in all practical contexts we operate in.

Disabling the warning could work, but that's a bit of build system work - checking for whether the warning option is supported has a few surprising pitfalls, as some compilers silently accept unknown warning options and then popping up warnings later, see https://github.com/llvm/llvm-project/commit/e546bbfda0ab91cf78c096d8c035851cc7c3b9f3.

So if possible to write code that in itself is mostly warnings free with modern compilers, I kinda prefer that.

// Martin

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

Reply via email to