сб, 24 авг. 2024 г. в 14:20, LIU Hao <[email protected]>: > I think that linking MS CRT within a Cygwin program could be dangerous, as > Cygwin has its own CRT. > mingw-w64 headers should only be used to access Windows APIs.
As you previously said, this is potentially dangerous for functions that modify global state, like `malloc()`. As you can see in my example here: https://github.com/rkitover/cygwin-binary-with-ucrt-example , the CRT import library is after the Cygwin runtime import library in the link order, so these functions are less likely to be invoked. The danger is further reduced by the fact that the Cygwin runtime itself uses MSVCRT. However, the main issue is trivial functions like `stricmp()` or `sprintf_s()` which are safe and do not modify global state. Any that do, we could even declare to be a compile error. Actually now that I think about it, "crt/nonstd/" would be better than "crt-nonstd". Other than arbitrary Win32 API code, there is an existing problem with the headers relying on these non-standard MSVCRT functions themselves. For example, in my example here: https://github.com/rkitover/mingw-win32-get-parent-example I needed to do: #ifdef __CYGWIN__ #define sprintf_s sprintf #endif , because "comutil.h" has this definition: #define _COM_PRINTF_S_1(dest,destsize,format,arg1) sprintf_s(dest,destsize,format,arg1) Another possible solution, suppose we make a "nocrt/" subdirectory in headers, and e.g. "nocrt/stdio.h" would have: #include <stdio.h> #define sprintf_s sprintf , and "nocrt/string.h" would have: #include <strings.h> #define stricmp(s1, s2) strcasecmp(s1, s2) Then "windows.h" and "comutil.h" and anything else that may need that function would have: #ifndef _WIN32 #include <nocrt/stdio.h> #include <nocrt/string.h> ... #endif , etc.. Other than Cygwin runtime programs, there are other potential use-cases for supporting this, such as building arbitrary Win32 API code on Linux and other OSes using winelib, etc.. _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
