This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Program issue when compiled against Newlib
- From: Ian Seyler <ian dot seyler at returninfinity dot com>
- To: newlib at sources dot redhat dot com
- Date: Fri, 12 Aug 2011 10:26:47 -0400
- Subject: Program issue when compiled against Newlib
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