delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/01/01/11:37:45

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-0.3 required=5.0 tests=AWL,BAYES_00,FH_DATE_PAST_20XX,SARE_MSGID_LONG40,SPF_PASS
X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
In-Reply-To: <380-22009123301337494@cantv.net>
References: <380-22009123301337494 AT cantv DOT net>
Date: Fri, 1 Jan 2010 16:37:32 +0000
Message-ID: <416096c61001010837m39284257i3605e7261d21d257@mail.gmail.com>
Subject: 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
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

> 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 =C2=A0printf(char_array) =C2=A0does no=
t, even
> though =C2=A0it is
> =C2=A0affected 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=3DC should work wit=
hout
> 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019