newlib printf() stack usage

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by dpursell on Wed Aug 29 12:36:04 MST 2012

I'm working in C++ with newlib (nohost) and retargeting stdout to a UART. I am finding that printf() takes up an absurd amount of stack space. I realize it is a very complex function, but looking at the disassembly I'm seeing the internal function _vfprintf_r() reserve 1392 bytes on the stack plus registers. In addition this function recurses, meaning my printf() call is taking almost 3000 bytes on the stack.

My questions are:
1. Is there a way to modify the stack requirements for _vfprintf_r(), possibly by defining a maximum string size or something similar?
2. What condition causes _vfprintf_r() to recurse? Can _vfprintf_r() recurse more than once?

To be clear, I don't really care how much code space the function takes, I'm just concerned with the run-time stack requirements.

Thank you!