--- Begin Message ---
- From: Benjamin Kosnik <bkoz at redhat dot com>
- To: Paolo Carlini <pcarlini at unitus dot it>
- Date: Wed, 8 May 2002 08:58:49 -0700
- Subject: Re: Update on libstdc++/6410 (a.k.a. non-ascii mon. symbol AND wchar_t => chaos)
- Organization: Red Hat/San Francisco
- References: <3CD7CFFF.4020208@unitus.it>
- Reply-to: bkoz at nabi dot net
> Any idea useful to make some further progress?
Here's something to think about.
Take the following, mostly "C" code:
#define _GNU_SOURCE 1
#include <locale.h>
#include <string.h>
#include <wchar.h>
#include <langinfo.h>
#include <malloc.h>
int main()
{
const char* __name = "de_DE@euro";
__locale_t __cloc = __newlocale(1 << LC_ALL, __name, 0);
char* __old = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, __name);
const char* __ccurr = __nl_langinfo_l(__CURRENCY_SYMBOL, __cloc);
mbstate_t __state;
size_t __result;
size_t __len = strlen(__ccurr);
wchar_t* __wcs;
if (__len)
{
++__len;
__wcs = new wchar_t[__len];
memset(&__state, 0, sizeof(mbstate_t));
__result = mbsrtowcs(__wcs, &__ccurr, __len, &__state);
}
setlocale(LC_ALL, __old);
delete [] __wcs;
free(__old);
}
Then, looking at it in gdb:
(gdb) p __ccurr
$12 = 0x4003a0c5 "¤"
(gdb) p *__ccurr
$13 = -92 '¤'
then...
(gdb) p __wcs
$14 = (wchar_t *) 0x80adc40
(gdb) p *__wcs
$15 = 8364
both of these values are perhaps unexpected.
The good news is that the C++ code in your example program gives the
same values as the above.
Thoughts?
-benjamin
--- End Message ---