[RFC]New implementation of C89 streamio for resource limited bare metal systems

Freddie Chopin freddie_chopin@op.pl
Sat Jun 8 11:09:00 GMT 2013


W dniu 2013-06-08 12:44, Bin Cheng pisze:
> I missed the part that __sbprintf has been changed into non-inline, so the
> big buffer isn't a problem anymore. Though __sbprintf can be guarded by an
> option still.

Yes that's true - the function is not inlined anymore, so the 1024B (or 
other size if BUFSIZ is redefined) buffer is allocated on stack only if 
you use unbuffered stream. Anyway - I think it would be a nice option to 
disable this optimization, so that unbuffered streams would not use so 
much stack. For this reason I have to provide my own handling of assert 
failure - in MCUs I just don't see the normal version - using fiprintf() 
and this 1kB buffer (stderr is unbuffered) - working reliably.

>>> But one challenge is how to make floating point weak symbol without
>>> re-implement the stream io routines, because floating point is tight
>>> coupled with integer in current implementation.
>>
>> Well, if you don't want to use floating point AT ALL you can just redefine
> all
>> *printf to be *iprintf (and the same for scanf). I guess it would be
> enough to
>> have sth like this added to compilation:
>>
>> -Dprintf=iprintf -Dfprintf=fiprintf -Dsprintf=siprintf ...
>> -Dscanf=iscanf -Dfscanf=fiscanf -Dsscanf=siscanf ... (for all available
>> "types" of these functions)
> It requires lots of change of command line options, but yes, this should
> work.

It's probably possible to do that with linker script, but I'm not sure 
how to do that in a generic way. Doing sth like this:

EXTERN(siprintf);
sprintf = siprintf;

works (you call sprintf, but siprintf is actually called), but this has 
a problem that each symbol within EXTERN will be linked, even if not 
used... And without EXTERN there's a linker script error that siprintf 
symbol is undefined...

4\/3!!



More information about the Newlib mailing list