<?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: Float to char array corrupting values in Classic/Legacy CodeWarrior</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Float-to-char-array-corrupting-values/m-p/185901#M4491</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could be either that T? destination buffers are overwritten or the default stack space allocated in the prm file might also be too small. What areas got overwitten? The P2/T2 arrays or other globals? Try to increase the STACKSIZE in the prm file (also search for that in the forum, with floats/doubles the default STACKSIZE is often too small.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A simple float to buffer formatting routine might need less stack and also be considerably smaller than sprintf.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 04 Aug 2012 10:34:46 GMT</pubDate>
    <dc:creator>CompilerGuru</dc:creator>
    <dc:date>2012-08-04T10:34:46Z</dc:date>
    <item>
      <title>Float to char array corrupting values</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Float-to-char-array-corrupting-values/m-p/185900#M4490</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN&gt;Using CW 10.2, JM60 micro full chip simulation.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code calculates pressures and temperatures from ADC values and outputs them to a display that accepts ascii characters. &amp;nbsp;Trying to use the sprintf to convert between float and ASCII. &amp;nbsp;When the sprintf lines execute the result loads into the variable locations correctly, but it also corrupts a lot of other variables. &amp;nbsp;Guessing I am running into the overflow issue with sprintf, but I thought the format part would have fixed that. &amp;nbsp;Any suggestions on fixes or alternative methods?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//from header&lt;/P&gt;&lt;P&gt;struct Values&lt;BR /&gt;{&lt;BR /&gt;float T1;&lt;BR /&gt;float T2;&lt;BR /&gt;float T3;&lt;BR /&gt;float P1;&lt;BR /&gt;float P2;&lt;BR /&gt;float P3;&lt;BR /&gt;};&lt;BR /&gt;struct DisplayValues&lt;BR /&gt;{&lt;BR /&gt;char T1[64];&lt;BR /&gt;char T2[64];&lt;BR /&gt;char T3[64];&lt;BR /&gt;char P1[64];&lt;BR /&gt;char P2[64];&lt;BR /&gt;char P3[64];&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//from Main.c&lt;/P&gt;&lt;P&gt;struct Values Vals;&lt;BR /&gt;struct DisplayValues DispVals;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void Load_Display(void)&lt;BR /&gt;{&lt;BR /&gt;int res;&lt;BR /&gt;res = sprintf(DispVals.P1, "%6.3f", Vals.P1);&lt;BR /&gt;res = sprintf(DispVals.T1, "%4.1f", Vals.T1);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 04 Aug 2012 03:00:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Float-to-char-array-corrupting-values/m-p/185900#M4490</guid>
      <dc:creator>dm1001</dc:creator>
      <dc:date>2012-08-04T03:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: Float to char array corrupting values</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Float-to-char-array-corrupting-values/m-p/185901#M4491</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could be either that T? destination buffers are overwritten or the default stack space allocated in the prm file might also be too small. What areas got overwitten? The P2/T2 arrays or other globals? Try to increase the STACKSIZE in the prm file (also search for that in the forum, with floats/doubles the default STACKSIZE is often too small.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A simple float to buffer formatting routine might need less stack and also be considerably smaller than sprintf.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 04 Aug 2012 10:34:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Float-to-char-array-corrupting-values/m-p/185901#M4491</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2012-08-04T10:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: Float to char array corrupting values</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Float-to-char-array-corrupting-values/m-p/185902#M4492</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Also a note about the formatting argument of sprintf. Note that for the printf format width only defines the minimal width which will be used. So sprintf(buffer,&amp;nbsp;&lt;SPAN&gt;"%10f", 1.0F) will always print 10 characters (space filed), it does NOT limit the maximum number of characters&amp;nbsp;written.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;E.g. sprintf(buffer, "%1.1f", 1E10) will still print "100000&lt;SPAN&gt;00000.0"&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;The reason why I don't think in your code the destination buffer overflows is that for IEEE32 floats, the largest float only has 3.4 E38, so with a negative sign, a decimal dot and a few digits after the decimal dot, the max output should still be less than 64 characters, So I guess in your case, you instead run into a overflow, can happen with any code, but with floats/sprintf its much more likely.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Daniel&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 04 Aug 2012 11:03:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Float-to-char-array-corrupting-values/m-p/185902#M4492</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2012-08-04T11:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: Float to char array corrupting values</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Float-to-char-array-corrupting-values/m-p/185903#M4493</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Daniel,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Default stack size was 0x80, searched for the issue and saw people having trouble even at 0x100. &amp;nbsp;Upped mine to 0x200 as they did to fix their problem and it worked for me. &amp;nbsp;In response to your question it was corrupting other global variables. &amp;nbsp;&lt;SPAN&gt;Thanks for the help.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Aug 2012 18:48:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Float-to-char-array-corrupting-values/m-p/185903#M4493</guid>
      <dc:creator>dm1001</dc:creator>
      <dc:date>2012-08-06T18:48:59Z</dc:date>
    </item>
  </channel>
</rss>

