在 2026-1-23 01:17, Pali Rohár 写道:
Ok, I would not use them in future changes. Personally I thought that
GNU ?: operator makes code more readable and more compact. That is why I
used C ? : operator and GNU ?: operator.

Casting between function pointers requires an intermediate cast to
`intptr_t` or `void*`, otherwise compilers will warn about it.

In this case, the cast is not needed because FARPROC (returned by
GetProcAddress) and typeof(IsDBCSLeadByteEx) have same return value and
same calling convention. That is why I have not used it in this time.

Anyway, to be more precise or pedantic, casting between function and
data pointers may cause other warnings as such casting is not defined in
C. Maybe those warning will appear only with -pedantic or similar flags,
I'm not sure now.

Some compilers deliberately warn about casts between incompatible function pointers, but they don't warn casts between function pointers and `void*`. That's why Martin asked you to make patches pass the CI -- we have `-Werror` in there.


The correct way should be casting it via intermediate (void(*)(void))
function pointer which does not generate any warning for neither gcc,
clang and msvc. CRT headers have for it special type _PVFV. So the most
correct way should be something like:

   farproc = (FARPROC)(_PVFV)fallback_IsDBCSLeadByteEx;

I have simplified this a little [2][3]:

     FARPROC farproc = NULL;
     HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
     if (kernel32)
       farproc = GetProcAddress(kernel32, "IsDBCSLeadByteEx");
     if (!farproc)
       farproc = (FARPROC)(PVOID)fallback_IsDBCSLeadByteEx;
     (void)InterlockedExchangePointer((PVOID*)&call_IsDBCSLeadByteEx, 
(PVOID)farproc);

Despite these issues, the changes are very simple and straight forward. If
these changes pass the CI, I can push them tomorrow.

[2] 
https://github.com/lhmouse/mingw-w64/commit/a22c8e74f2ab108b18758aa2ae2a8334e999eca7
[3] 
https://github.com/lhmouse/mingw-w64/commit/cf3a23755035c82e4de4d620caf4f2882857d6d0

Ok, that is fine.

I have pushed these now with those changes.


--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to