Re: printf functions fail with non-ascii characters
Re: printf functions fail with non-ascii characters
- Subject: Re: printf functions fail with non-ascii characters
- From: Fritz Anderson <email@hidden>
- Date: Wed, 5 Sep 2007 13:14:53 -0500
I have a couple of thoughts that may be helpful (for a given value of
helpful):
Gcc doesn't guarantee proper behavior with any character set for
source code other than 7-bit ASCII. That should end matters right
there. For constants (assuming you solve the problem of matching your
output encoding to the terminal or other consumers of your output) you
have to have a data file you read in at run time.
Standard C doesn't guarantee any particular encoding, or even size,
for wchar. You may be used to two-byte wchars; Gcc on Mac uses headers
and libraries for 4-byte wchars.
For the record, the source code is UTF-8, no BOM.
Strictly speaking, no it isn't. Not so far as gcc is concerned. Your
UTF-8 multibyte sequences are interpreted by the compiler as sequences
of 8-bit characters. Sometimes that works, but that's just luck.
Your data files are probably encoded as UTF-8 or -16. The C library
probably reads them as 32-bit characters. See if UTF-32 is available,
and works.
Terminal defaults to UTF-8 I/O. It can be made to use UTF-32.
These aren't Mac eccentricities; there is only non-portable code. This
is why there are libraries, like Foundation and Core Foundation, to
abstract such considerations.
— F
On Sep 5, 2007, at 12:40 PM, William H. Schultz wrote:
The wide character versions of the printf functions are failing with
various non-ascii characters, as can be seen with the following code:
#include <stdarg.h>
#include <wchar.h>
int main()
{
wchar_t buf[20];
va_list ap;
return vswprintf(buf, 20, L"トネヘ", ap);
}
In case the above doesn't properly survive the e-mail, that's just
three random Japanese characters in the test string. This code
returns -1 instead of the 3 that I would expect by looking at it.
The same is true for various other sets of non-ascii characters and
various other wide character printf functions.
I'm using Xcode 2.4.1 under 10.4.10 on an Intel machine. This is
with g++ version 4.0.1 (build 5367).
Any ideas?
-------------------------------
Hank Schultz
Cedrus Corporation
http://www.cedrus.com/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden