printf() woes

Jeff Johnston jjohnstn@redhat.com
Wed Jan 30 23:34:00 GMT 2008


Rick Mann wrote:
> 
> On Jan 30, 2008, at 11:10 AM, Jeff Johnston wrote:
> 
>> Rick Mann wrote:
>>> Hi. I'm using newlib 1.14 on an Atmel ARM processor, and printf() is 
>>> behaving strangely.
>>> The following code
>>>    printf("1. Hello worldCRLF1\r\n");
>>>    printf("2. Hello worldCRLF\r\n");
>>>    printf("3. Hello worldCRLF\r\nHello worldCRLF\r\n");
>>>    printf("4. Hello worldLF\nHello worldLF\n");
>>>    printf("5. Hello worldNULL");
>>>    printf("6. Hello worldLF\n");
>>> prints:
>>> 3. Hello worldCRLF1
>>> 4. Hello worldLF
>>>                Hello worldLF6. Hello worldLF
>>> Using snprintf() works just fine.
>>
>> Did you attempt to write the result out?
> 
> I'm not sure I understand what you mean. I put, in the original post, 
> the output of those lines of code. It fails to print many of them.

What I meant is did you output the snprintf() output to the terminal
(e.g. via write syscall) to see what that output produces on the 
terminal.  It may not be newlib's problem.

> 
>>> Newlib's printf() is doing something with newlines, and printf() 
>>> calls without newline, and not handling it the way I really want. 
>>> Perhaps it's a configuration things somewhere, but I don't really 
>>> know where to look.
>>> Any suggestions?
>>
>> I would suggest upgrading to newlib 1.16.0 to see if any fixes were 
>> made that solve your problem.  Looking through the ChangeLog, none are 
>> obvious, but it still helps to be current so others can better help you.
> 
> Is there a way to upgrade newlib without rebuilding all of gcc?
> 

Yes.  You can build newlib in a separate build directory.  Just make 
sure you have installed all the cross-tools (including gcc) somewhere 
and put the install dir on your path.

>> Next, I would suggest debugging inside _sfvwrite() to see what it 
>> thinks it is doing.  I would also suggest putting breakpoints inside 
>> the _write syscall to see what it is being called with each time.  
>> This should help you pinpoint the problem.
> 
> Sadly, I have no debugging capabilities right now (other than printf--ha!).
> 

Ok, use the write syscall to fd 2.

-- Jeff J.



More information about the Newlib mailing list