my understanding is that most implementations of printf rely on something like
vsnprintf( _acBuffer[0], sizeof( _acBuffer[0] ), pcFormat, *ptArgList );
to actually handle the formatting and then they output them to the stream via puts.
Are there any implementation that minimize the size of _acBuffer[0] required while maintaining the ability to print all string?
Obviously something like :
printf("%s", pcReallyLongString);
would be a problem.
Your thoughts are much appreciated!
Your understanding is just wrong. I’ve never seen or heard of a
printfimplementation that works by first formatting the entire output to a temporary string buffer. Usually printf is done the other way around: the fundamental building block isvfprintfandvsnprintfis a wrapper for that which creates a fakeFILEwhose buffer is the destination string.Edit: Some popular (e.g. glibc) implementations do make some use of unboundedly-large intermediate buffers for certain formats, especially wide character conversions, and will fail unpredictably when they cannot allocate sufficient memory for the buffer. This is purely a low-quality-implementation issue, however; there’s no fundamental reason any of the
printffunctions should require any more than a small constant amount of working space, regardless of what they’re printing.