Re: Problem with '€' (EURO) symbol in (U)CRT |printf("%S", ...);| ...

Thomas Wolff towo@towo.net
Mon Dec 2 18:04:15 GMT 2024


Am 02.12.2024 um 18:01 schrieb Roland Mainz via Cygwin:
> On Wed, Nov 27, 2024 at 1:49 AM Brian Inglis via Cygwin
> <cygwin@cygwin.com> wrote:
>> On 2024-11-26 17:08, Roland Mainz via Cygwin wrote:
>>> Cygwin 3.5.4/Win10/64bit, the following program prints a '?' where I
>>> would expect a '€' (EURO) symbol:
>>> ---- snip ----
>>> printf '#include <stdio.h>\n#include <wchar.h>\n#include
>>> <io.h>\n#include <fcntl.h>\n#include <locale.h>\nint main(int ac, char
>>> *av[]) { setlocale(LC_ALL, ""); printf("%%S\\n", L"hello € world");
>>> return 0; }\n' >x.c && clang -target x86_64-pc-windows-gnu -Wall x.c
>>> -o x.exe && ./x.exe
>>> hello ? world
>>> ---- snip ----
>>>
>>> My hope was that - because Win32 uses UTF-16 for |wchar_t| - that the
>>> EURO symbol can be displayed on any locale/code page which supports
>>> the EURO symbol, but somehow I always get a '?'.
>>>
>>> Does anyone know what I am doing wrong ?
>> $ grep -aw EURO ~/src/charsets/unicode-symbols.txt
>> ₠  U+20A0   EURO-CURRENCY SIGN
>> €  U+20AC   EURO SIGN
>> 💶 U+1F4B6  BANKNOTE WITH EURO SIGN
>>
>> What is your terminal locale and charset?
> LC_ALL=en_US.UTF-8.
>
> But it turns out my issue is a bit UCRT-specific:
> It seems UCRT |printf()| is not able to print wide-char values in all
> locales/codepages - instead I have to use |wprintf()| and
> |_setmode(_fileno(stdout), _O_WTEXT);|.
> Unfortunate side-effect is that putting stdout/stderr in wide-char
> mode makes any attempt to do a single-char |printf()| fail with an
> assert.
This is not UCRT-specific, same on cygwin. It works if you drop the
-target x86_64-pc-windows-gnu
>
> Cygwin's native stdio doesn't have that limitation.
>
> But now I am a bit cursing because of this little issue from
> https://learn.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=msvc-170
> ---- snip ----
> ... For historical reasons, the wprintf functions use c and s to refer
> to wchar_t characters, and C and S specify narrow characters. ...
> ---- snip ----
> ... but it turns out that at least in UCRT you can |#define
> _CRT_STDIO_ISO_WIDE_SPECIFIERS 1| to fix this.
>
> Question is in which Windows or Visual Studio version added this feature...
>
> ----
>
> Bye,
> Roland


More information about the Cygwin mailing list