On Wednesday 11 March 2026 14:09:43 LIU Hao wrote:
> 在 2026-3-6 17:45, Kirill Makurin 写道:
> > LIU Hao wrote:
> > > But that's not standard behavior. I think we're too late for such 
> > > changes; people who have been used to
> > > the standard behavior would be annoyed.
> > 
> > Those %C and %S format specifiers are not part of standard C; they are 
> > however part of Single Unix Specification, and correspond to %lc and %ls 
> > respectively. IMO, there are zero reasons why anyone would use them in 
> > portable code since we have standardized %lc and %ls for this purpose.
> 
> Right, POSIX is also a standard, and for stdio functions it stays as an
> extension to ISO C. So standard `c`/`s` references a narrow
> character/string, and standard `C`/`S` references a wide character/string.
> 
> 
> > Microsoft's printf functions also support %C and %S with incompatible 
> > meaning.
> > See 
> > https://learn.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions.
> > 
> > Standard-conforming code should never use %C and %S since this is undefined 
> > behavior, so I don't really see compatibility issues here. IMO, providing 
> > consistent Microsoft behavior among all CRTs is a compatibility improvement.
> 
> There's risk that someone has been abusing `%S` in `swprintf()` to
> incorporate a `char*` argument. This is quite arguable, but really they
> should use `%hs`.

When mingw-w64 switched the default build from msvcrt to UCRT, it also
switched swprintf %S from wchar_t* to char* because it switched from
mingw-w64 printf to MS printf implementation. This already happened in
the past and I did not found reported issues about it related to %Č and
%S formats.

My change here affects only non-default mingw-w64 builds (msvcrt) or
when compiling applications with additional -D flags.

IMHO bigger risk was the %S change which happened in the past for
default builds than this my change.


Anyway, msvc supports _CRT_STDIO_ISO_WIDE_SPECIFIERS and
_CRT_STDIO_LEGACY_WIDE_SPECIFIERS defines which explicitly choose the
behavior of %S / %C formats. Maybe we can extend the mingw-w64 header
files via asm forward directive to also support these macros and
redirect to functions with char* vs wchar_t* support.


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

Reply via email to