Any function instead of sprintf() in C? code size is too big after compile

Django picture Django · Oct 25, 2012 · Viewed 14.5k times · Source

I am working on developing an embedded system (Cortex M3). For sending some data from the device to the serial port (to show on a PC screen), I use some own functions using putchar() method.

When I want to send integer or float, I use sprintf() in order to convert them to string of characters and sending them to the serial port.

Now, them problem is that I am using Keil uVision IDE and it is limited version with max 32 KB. Whenever I call sprintf() in different functions, I don't know why the size of the code after compile increased too much. I have surpassed 32 KB now and I wonder I have to change some of my functions and use something else instead of sprintf!

Any clue?

Answer

Martin Thompson picture Martin Thompson · Oct 25, 2012

Two potential offerings (neither of which I have used myself - my compiler vendors usually supply a stripped down printf for embedded use):

http://eprintf.sourceforge.net/ - [Sep 2017: unfortunately, seems to have gone away, but source code still here: https://sourceforge.net/projects/eprintf/files/ ]

http://www.sparetimelabs.com/tinyprintf/index.html - 2 files, about 1.4KB code. Option to enable 'longs' (means more code size). Supports leading zeros and field widths. No floating point support.