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: Mon, 28 Dec 2009 22:37:57 +0000
- Subject: Re: gcc4[1.7] printf treats differently a string constant and a character array
- References: <380-2200912128193944786@cantv.net>
2009/12/28 Rodrigo Medina:
> Hi,
> I am moving from cygwin-1.5 and gcc3.4 to cygwin1.7 and gcc4.
> Some simple programs of mine fail.
>
> I am using LC_ALL=es_VE.ISO-8859-15.
>
> I have reduced the problem to this example
>
> --------------
> #include <stdio.h>
> main()
> {
> static char* line1 =
> " This letter has an accent -->Ã, this one has no accent -->a\n\n";
> static char* line2 = " ***** another line ******\n\n";
> static char* line3 =
> " These letters have an accent -->ÃÂ, these ones have no accent -->A!\n\n";
> static char* line4 =
> " This letter has an accent -->Ã, this one has no accent -->A\n\n";
> Âprintf(" This letter has an accent -->Ã, this one has no accent
> -->a\n\n");
> Âprintf(line2);
> Âprintf("%d %d %d\n\n",line1[29],line1[30],line1[31]);
> Âprintf(line1);
> Âprintf(line2);
> Âprintf(" These letters have an accent -->ÃÂ, these ones have no accent
> -->A!\n\n");
> Âprintf(line2);
> Âprintf("%d %d %d %d\n\n",line3[32],line3[33],line3[34],line3[35]);
> Âprintf(line3);
> Âprintf(line2);
> Âprintf(" This letter has an accent -->Ã, this one has no accent
> -->A\n\n");
> Âprintf(line2);
> Âprintf("%d %d %d\n\n",line4[29],line4[30],line4[31]);
> Âprintf(line4);
> Âprintf(line2);
> Âprintf(" ----- END ------");
> }----------------
>
> My output is:
>
> ÂThis letter has an accent -->Ã, this one has no accent -->a
>
> Â***** another line ******
>
> 62 -31 44
>
> ÂThis letter has an accent --> ***** another line ******
>
> ÂThese letters have an accent -->ÃÂ, these ones have no accent -->A!
>
> Â***** another line ******
>
> 62 -61 -95 44
>
> ÂThese letters have an accent -->ÃÂ, these ones have no accent -->A!
>
> Â***** another line ******
>
> ÂThis letter has an accent -->Ã, this one has no accent -->A
>
> Â***** another line ******
>
> 62 -61 44
>
> ÂThis letter has an accent --> ***** another line ******
>
> Â----- END ------
>
> As you can see the output of printf(string_constant) is what
> I expected. The ouput of printf(char_array) is trucated at the non-ASCII
> character.
Reproduced. Looking at the compiler's assembly output, some of the
printf() calls are replaced by calls to puts(), and those do work
correctly, whereas the remaining printf() calls with accented
characters misbehave. So printf()'s handling of non-ASCII characters
needs a closer look.
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