On Thursday 18 December 2025 06:23:08 Kirill Makurin wrote:
> This patch series adds missing _CRTIMP in declarations of some functions in
> several header files. There are still many places where _CRTIMP is missing,
> I'll try to take care of them later.
>
> There are a few things I've noticed and would like to mention:
>
> First, we have duplicating (guarded) declarations in multiple header files,
> such as various wcs* functions are declared in both wchar.h and string.h.
> Should we move them to a separate header file, similarly to what MSVC does,
> with headers like correct_wchar.h?
>
> Second, mingw-w64 ctype.h declared four functions as external: isascii,
> toascii, iscsymf and iscsym. They all are aliases for the same functions but
> with two leading underscores (e.g. __isascii). They are declared with
> _CRTIMP, which does not seem correct to me. MSVC does not provide these four
> functions as externals, so I think it would be better to remove _CRTIMP.
>
> Third, should we add _CRTIMP at least for some of wcs*/str* functions, such
> as {wcs,str}spn? It seems that MSVC declares at least
> {wcs,str}{cspn,spn,pbrk} with _ACRTIMP, so I think it safe to add _CRTIMP at
> least for those? I hesitate to touch the rest.
>
> Results of GitHub CI run for this patch series are here[1].
>
> - Kirill Makurin
>
> [1] https://github.com/maiddaisuki/mingw-w64/actions/runs/20325886194
Generally, inline functions can cause issues. In C it is not possible to
take pointers for them, or pointer can have different value in each
compiled unit.
This can be fixed by using gnu_inline, but it always requires to have
external definition.
In some cases having gnu_inline together with external definition can be
useful for optimization purposes.
Generally, gnu_inline variants can be useful for optimization purposes.
As it fixes problem with taking pointers and also allow to provide
non-trivial wrappers.
Also note that if we have two function declarations in header file for
one DLL function (e.g. _stricmp and strcasecmp), then usage of both
functions will generate PE IMPORT TABLE where the _stricmp is imported
two times. Usage of gnu_inline function can prevent it have just one
entry for _stricmp PE IMPORT TABLE.
> From 79b1e6f4bc88a39f7b9bf79cdda2cc749c0c0c10 Mon Sep 17 00:00:00 2001
> From: Kirill Makurin <[email protected]>
> Date: Thu, 18 Dec 2025 13:02:33 +0900
> Subject: [PATCH 2/9] crt: add missing _CRTIMP for functions declared in
> assert.h
>
> Signed-off-by: Kirill Makurin <[email protected]>
> ---
> mingw-w64-headers/crt/assert.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mingw-w64-headers/crt/assert.h b/mingw-w64-headers/crt/assert.h
> index bce9a57cf..a8cfb2e83 100644
> --- a/mingw-w64-headers/crt/assert.h
> +++ b/mingw-w64-headers/crt/assert.h
> @@ -22,7 +22,7 @@ extern "C" {
> #endif
>
> _CRTIMP void __cdecl __MINGW_ATTRIB_NORETURN _wassert(const wchar_t
> *_Message,const wchar_t *_File,unsigned _Line);
> -void __cdecl __MINGW_ATTRIB_NORETURN _assert (const char *_Message, const
> char *_File, unsigned _Line);
> +_CRTIMP void __cdecl __MINGW_ATTRIB_NORETURN _assert (const char *_Message,
> const char *_File, unsigned _Line);
>
> #ifdef __cplusplus
> }
> --
> 2.51.0.windows.1
>
I'm fine with those changes except this one. We have removed _CRTIMP for
_assert just recently because _assert was completely replaced by
mingw-w64 implementation and so having _CRTIMP just:
1) falsely provides impression that function in imported, even is not
2) requires additional layer of redirection to call the mingw-w64 function
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public