This is the mail archive of the mailing list for the newlib project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

getchar issues


I am using the following small test program linked against
newlib-1.14.0 on my embedded PowerPC target.

      1 #include "stdio.h"
      3 int main (void)
      4 {
      5     char c;
      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 -

I will debug this further, but are there any obvious things I should
be checking? Any help is much appreciated.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]