This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
getchar issues
- From: "Matt Lee" <reachmatt dot lee at gmail dot com>
- To: newlib at sources dot redhat dot com
- Date: Mon, 10 Mar 2008 12:20:20 -0700
- Subject: getchar issues
Hi,
I am using the following small test program linked against
newlib-1.14.0 on my embedded PowerPC target.
1 #include "stdio.h"
2
3 int main (void)
4 {
5 char c;
6
7 //printf("Enter a character:\r\n");
8 while (1) {
9 c = getchar();
10 printf("Char: %c. Hex:0x%x.\r\n", c, c);
11 }
12 }
In the above program the first character returned by getchar() in the
loop seems to be some random junk and not the character typed on the
console. That is, I always get a "H" before getting the correct
characters typed in sequence.
If line 7 is *not* commented out, then getchar returns the character
typed correctly without any extraneous incorrect characters.
I have verified that my read() implementation is not the one returning
the crud. A wild theory from me is that the program flow through
printf() is enabling or initializing some structure that the program
flow through getchar() is not.
I am using -DSMALL_MEMORY -D_REENT_SMALL in the newlib C flags during
build and also have _REENT_SMALL defined in sys/config.h for my
architecture. I have also backported and applied two bug fixes
(below) related to _REENT_SMALL -
http://sourceware.org/ml/newlib/2006/msg00037.html
http://sourceware.org/ml/newlib/2006/msg00796.html
I will debug this further, but are there any obvious things I should
be checking? Any help is much appreciated.
--
thanks,
Matt