gcc4[1.7] printf treats differently a string constant and a character array
Rodrigo Medina
rodmedina@cantv.net
Mon Dec 28 19:40:00 GMT 2009
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.
But not always the printf(char_array) fails. The couple of
characters "á" are printed correctly. Nevertheless the character "Ã"
alone fails.
For whateveri that could mean, notice that "á" corresponds to the UTF-8
encoding of "á", so that the character array is an acceptable UTF-8
string, but what is actually printed is not the UTF-8 string but the
ISO-8859-15 string.
Happy Holiday and thanks for the great work of cygwin1.7 !
RM
The cygcheck output and the environment are attached.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: environ.txt
URL: <http://cygwin.com/pipermail/cygwin/attachments/20091228/6092d6d7/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cygcheck.txt
URL: <http://cygwin.com/pipermail/cygwin/attachments/20091228/6092d6d7/attachment-0001.txt>
-------------- next part --------------
--
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
More information about the Cygwin
mailing list