AnsweredAssumed Answered

Reducing printf sprintf scanf footprint does not work as expected

Question asked by ROBERTO BERNER on May 13, 2007
Latest reply on May 13, 2007 by CompilerGuru
A Metrowerks FAQ document explains the way to dramatically reduce code generated by the use of printf / scanf functions. This is an usual procedure in most good compilers. In my case I am not using floats. The document indicates the following steps that I have implemented in my 5.1 version for the HC08:

****************
FAQ Libraries:

Q Footprint from function “printf” is too big. How can I reduce the code size for this function?
A In fact according to the ANSI C standard, the function printf must support a lot of different formats.

This is the main reason why this function takes so much memory.
As we know that the amount of memory is limited on an embedded processor, there is a way to
minimize the footprint for the function printf.

?? Add the file printf.c located in your LIB\HC08c\src installation directory to your project.
?? In the "Link Order" view make sure the file printf.c comes before the file ansi.lib. Use drag and
drop to bring the file ansi.lib at the end of the list for example.
?? Edit the file "libdefs.h" located in your LIB\HC08c\include installation directory.
?? In this file, there is a couple of macros, which can be modified to minimize the amount of code
in the function vprintf. The macros are defined around line 180.
For instance setting LIBDEF_PRINTF_FLOATING to 0 will reduce the code drastically. Be
careful, with this modification the customer will not be able to format floating point values
(float, double) any more.
Usage of each macro is explained in the header file. So you should be able to adjust the
function vprintf to your own needs.
?? Now build the application.

****************

Followed the instructions strictly, removed all of the object code and recompiling, there is no change in the ouput file size. The file is very explicit about the effects when editing. I have just included the following line at the top of the libdefs.h file:

#define __NO_FLOAT__ 1

Any idea of how to make it work will be very much appreciated. Thank you !

BooleanBob



Outcomes