This is the mail archive of the newlib@sourceware.org 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]

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


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