This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: gcc4[1.7] printf treats differently a string constant and a character array
- From: Andy Koppe <andy dot koppe at gmail dot com>
- To: rodmedina at cantv dot net, cygwin at cygwin dot com
- Date: Fri, 1 Jan 2010 16:37:32 +0000
- Subject: Re: gcc4[1.7] printf treats differently a string constant and a character array
- References: <380-22009123301337494@cantv.net>
> Some comments:
> 1- I think that printf(string_constant) and printf(char_array) should give
> the same
> output in any circumstance.
> 2- In absence of a call to setlocale printf((string_constant) writes
> according to
> the locale of the environment, but Âprintf(char_array) Âdoes not, even
> though Âit is
> Âaffected by the locale of the environment.
No, both work according to the "C" locale, with its UTF-8 character
set, and behaviour for invalid UTF-8 sequences is undefined for both.
"Undefined" means anything might happen, including inconsistent
behaviour. (Requiring consistent behaviour would make the puts
optimisation impossible.)
> 3- I think that a program that was written for locale=C should work without
> modification
> if the locale in the environment is any of the one-byte characters ones.
> 4- I think that a plain C (8-bit transparent) locale should be available,
> even if it
> is not the default one.
If you don't call setlocale, all you can expect according to the C and
POSIX standards is the so-called portable character set. So you
shouldn't assume that the C locale is 8-bit transparent.
However, since that is a valid assumption on Linux and others, Cygwin
might indeed be better off following their example. There's a
discussion about that on cygwin-developers.
Andy
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple