Reducing printf sprintf scanf footprint does not work as expected

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Reducing printf sprintf scanf footprint does not work as expected

Jump to solution
1,898 Views
BooleanBob
Contributor IV
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



Labels (1)
Tags (1)
0 Kudos
1 Solution
376 Views
CompilerGuru
NXP Employee
NXP Employee
There are 3 versions of every library delivered. One without floating point, one with "just" IEEE32 and one with IEEE64.
If you link against the library without floating point, then you already have a printf without the floating point support, could that be the reason for the behavior you observe?
The FAQ may still be useful for other purposes, like if your application does use floating point for other operations and not for sprintf. Or if your application does not need the long or octal support sprintf provides.

Also note that #define __NO_FLOAT__ 1 can also be done via -D__NO_FLOAT__=1 compiler command line option. I think wizard generated projects where no floating point support  was chosen have this option (not 100% sure).

Daniel




Message Edited by CompilerGuru on 2007-05-13 10:23 PM

View solution in original post

0 Kudos
1 Reply
377 Views
CompilerGuru
NXP Employee
NXP Employee
There are 3 versions of every library delivered. One without floating point, one with "just" IEEE32 and one with IEEE64.
If you link against the library without floating point, then you already have a printf without the floating point support, could that be the reason for the behavior you observe?
The FAQ may still be useful for other purposes, like if your application does use floating point for other operations and not for sprintf. Or if your application does not need the long or octal support sprintf provides.

Also note that #define __NO_FLOAT__ 1 can also be done via -D__NO_FLOAT__=1 compiler command line option. I think wizard generated projects where no floating point support  was chosen have this option (not 100% sure).

Daniel




Message Edited by CompilerGuru on 2007-05-13 10:23 PM
0 Kudos