This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Use of Sprintf increases code size!!

Hi,
When i use the following code, the code size is as below:
unsigned char Buf[3];
unsigned long oncount = 0;

sprintf (Buf,"%d",(int)(oncount/360000));
Program Size: data=45.1 xdata=1 code=1847

And when i dont use the Sprintf my code size gets reduced as below:
Program Size: data=24.0 xdata=1 code=558

Is there any alternate for Sprintf ??

Aniket

Parents
  • Look at the documentation of sprintf in the manual: just the description of all the formats and options runs to several pages - and then there's the handling of the variable-length arguments, parsing the format string, etc...

    All this versatility & mighty functionality doesn't come cheap - it obviously take a lot of code to implement all that stuff!

    "Is there any alternate for Sprintf ??"

    Sure - if you just want to create the signed decimal string representation of an 'int', then write a function which does just that and nothing else!

Reply
  • Look at the documentation of sprintf in the manual: just the description of all the formats and options runs to several pages - and then there's the handling of the variable-length arguments, parsing the format string, etc...

    All this versatility & mighty functionality doesn't come cheap - it obviously take a lot of code to implement all that stuff!

    "Is there any alternate for Sprintf ??"

    Sure - if you just want to create the signed decimal string representation of an 'int', then write a function which does just that and nothing else!

Children