<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Replacing Printf() &amp; sprintf() Functions in Classic/Legacy CodeWarrior</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Replacing-Printf-sprintf-Functions/m-p/199170#M5282</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check out &lt;A href="http://www.freescale.com/webapp/sps/utils/SingleFaq.jsp?FAQ-27705.xml" rel="nofollow" target="_self"&gt;FAQ-27705&lt;/A&gt;, which has a code example of a function that converts an integer to a string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;---Tom&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by J2MEJediMaster on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-09-14&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;03:18 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 15 Sep 2009 01:02:59 GMT</pubDate>
    <dc:creator>J2MEJediMaster</dc:creator>
    <dc:date>2009-09-15T01:02:59Z</dc:date>
    <item>
      <title>Replacing Printf() &amp; sprintf() Functions</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Replacing-Printf-sprintf-Functions/m-p/199167#M5279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OK interesting issue that I have been told has happened before and has been solved by developers writing their own versions of printf().&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using Codewarrior for DSC56800/E 8.1.1a and my target is the 56F8323 which has 32K of program space.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My issue is I am running out of codespace.&amp;nbsp; I have turned on Optimizations to level 3 and it is set for smaller code over speed.&amp;nbsp; I am still bumping into the code size limit and I have been going back through my code and optimizing where I can manually (which is a good thing).&amp;nbsp;I have also used Processor Expert to generate a lot of my code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In analyzing code usage I find that the excess bloat is not necessarily from PE but from some of the libs themselves.&amp;nbsp; I use sprintf a lot to format my strings before I then transmit them to the outside world.&amp;nbsp; Now I know I can modify putchr() to talk directly with a Serial port but I am actually using both ports and some parallel bits to get my data to the outside world so that is not really the best option.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In looking at the map file it appears that the printf.o is a huge codespace hog:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; address&amp;nbsp;&amp;nbsp;&amp;nbsp; size&lt;/P&gt;&lt;P&gt;&amp;nbsp; 000026AA 000002C9 .text&amp;nbsp;&amp;nbsp; Fparse_format&amp;nbsp;(MSL C 56800E.lib printf.o&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; 00002973 00000172 .text&amp;nbsp;&amp;nbsp; Flong2str&amp;nbsp;(MSL C 56800E.lib printf.o&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; 00002AE5 000000BA .text&amp;nbsp;&amp;nbsp; Fround_decimal&amp;nbsp;(MSL C 56800E.lib printf.o&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; 00002B9F 000003D3 .text&amp;nbsp;&amp;nbsp; Ffloat2str&amp;nbsp;(MSL C 56800E.lib printf.o&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; 00002F72 0000036C .text&amp;nbsp;&amp;nbsp; F__pformatter&amp;nbsp;(MSL C 56800E.lib printf.o&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; 000032DE 0000002B .text&amp;nbsp;&amp;nbsp; F__StringWrite&amp;nbsp;(MSL C 56800E.lib printf.o&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; 00003309 00000039 .text&amp;nbsp;&amp;nbsp; Fvsnprintf&amp;nbsp;(MSL C 56800E.lib printf.o&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; 00003342 0000000D .text&amp;nbsp;&amp;nbsp; Fsprintf&amp;nbsp;(MSL C 56800E.lib printf.o&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/P&gt;&lt;P&gt;I have had another developer tell me they have handled this issue by writing their own printf() function.&amp;nbsp; So my questions to the community:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Can writing your own printf() funtion really save you a lot of code space?&lt;/P&gt;&lt;P&gt;2) If you write your own printf() funtion how do you call it?&amp;nbsp; Do you need to rename the function to something like myprintf()?&amp;nbsp; How does that keep other lib functions (such as string handlers) from calling the original printf() and therefore still adding the bloat?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So if anyone who can point me to a good book or internet link on this subject I would be most appreciative.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jul 2009 23:21:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Replacing-Printf-sprintf-Functions/m-p/199167#M5279</guid>
      <dc:creator>v_dave</dc:creator>
      <dc:date>2009-07-14T23:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Printf() &amp; sprintf() Functions</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Replacing-Printf-sprintf-Functions/m-p/199168#M5280</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;if your question is still urgend, then I have a small version (not all options are included, but can be adapted):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.freescale.com/files/community_files/CFCOMM/6728_sprintf.c" rel="nofollow" target="_self"&gt;sprintf.c&lt;/A&gt;&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by t.dowe on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-09-11&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;11:30 AM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Sep 2009 18:24:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Replacing-Printf-sprintf-Functions/m-p/199168#M5280</guid>
      <dc:creator>t_wahl</dc:creator>
      <dc:date>2009-09-11T18:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Printf() &amp; sprintf() Functions</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Replacing-Printf-sprintf-Functions/m-p/199169#M5281</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;There is never a reason to use those functions in embedded systems, only PC programmers who don't know embedded programming use them. This opinion is shared by the widely recognized coding standard MISRA-C, rules 16.1 and 20.9.&lt;BR /&gt;&lt;BR /&gt;Replace printf() with a slim function for serial I/O or LCD print out. Roughly 100 - 200 bytes of code.&lt;BR /&gt;Replace sprintf() with a slim int to ASCII function. Roughly 100 bytes of code.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Sep 2009 19:45:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Replacing-Printf-sprintf-Functions/m-p/199169#M5281</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2009-09-11T19:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Printf() &amp; sprintf() Functions</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Replacing-Printf-sprintf-Functions/m-p/199170#M5282</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check out &lt;A href="http://www.freescale.com/webapp/sps/utils/SingleFaq.jsp?FAQ-27705.xml" rel="nofollow" target="_self"&gt;FAQ-27705&lt;/A&gt;, which has a code example of a function that converts an integer to a string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;---Tom&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by J2MEJediMaster on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-09-14&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;03:18 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Sep 2009 01:02:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Replacing-Printf-sprintf-Functions/m-p/199170#M5282</guid>
      <dc:creator>J2MEJediMaster</dc:creator>
      <dc:date>2009-09-15T01:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Printf() &amp; sprintf() Functions</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Replacing-Printf-sprintf-Functions/m-p/199171#M5283</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the info.&amp;nbsp; I am definetely still in need of the info. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have never really had an issue with sprintf() in the past since most of my embedded applications have not been as large as my current one.&amp;nbsp; All I am doing is combing some ASCII data with some numbers in a formatted string that will be sent out the serial port.&amp;nbsp; I was thinking that using one function rather than a couple of functions (Integer-&amp;gt;string followed by a strcpy() function) would have been cleaner and less overhead.&amp;nbsp; I knew sprintf() was a resource hog but did not know it was that significant.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All this info has really helped and thanks again for your insights.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Sep 2009 05:06:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Replacing-Printf-sprintf-Functions/m-p/199171#M5283</guid>
      <dc:creator>v_dave</dc:creator>
      <dc:date>2009-09-15T05:06:28Z</dc:date>
    </item>
  </channel>
</rss>

