This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: Program issue when compiled against Newlib
The serial I/O driver on your BareMetal OS isn't converting the '\r' that you used to terminate the input string into a "\r\n" when echoing -- on an old-fashioned paper terminal you'd see the two lines printed on top of each other.
On Aug 12, 2011, at 7:26 AM, Ian Seyler wrote:
> I have compiled NewLib for use in BareMetal OS but there seems to be
> an issue during program execution.
>
> Example Code:
> #include <stdio.h>
> #include <stdlib.h>
>
> char userinput1[160];
> char userinput2[160];
>
> int main()
> {
> printf("Please type your name: ");
> fgets(userinput1, 100, stdin);
> printf("Please type another word: ");
> fgets(userinput2, 100, stdin);
> printf("Hello %s", userinput1);
> printf("Word was %s", userinput2);
> printf("Goodbye.\n");
>
> return 0;
> }
>
> Program compiled with the regular C library and run under Ubuntu:
> Please type your name: Ian
> Please type another word: Test
> Hello Ian
> Word was Test
> Goodbye.
>
> Program compiled against Newlib and run under BareMetal OS:
> Please type your name: Ian
> Please type another word: Test
> Hello Ian
> Word was Goodbye.
>
> With debugging enabled under BareMetal OS I can see that both strings
> are populated with the data that was entered. However the last string
> displayed on the screen is "Word was Goodbye." in one call to the OS.
> Does anyone have a hint on this? Seems like an issue with printf().
> Does GCC optimize it somehow?
>
> Best regards,
> Ian
>
>
> --
> Ian Seyler | Founder / Lead Programmer | Return Infinity |
> ian.seyler@returninfinity.com | visit us at www.returninfinity.com
--
Eric Norum
eric@norum.ca