<?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: sprintf bug when using newlib nano with &amp;quot;-u _printf_float&amp;quot; linker option in S32 Design Studio</title>
    <link>https://community.nxp.com/t5/S32-Design-Studio/sprintf-bug-when-using-newlib-nano-with-quot-u-printf-float-quot/m-p/816470#M3687</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;Have you tried to install Update 2 ?&amp;nbsp;&lt;A href="https://community.nxp.com/docs/DOC-340534"&gt;S32 Design Studio for Power Architecture 2017.R1 - Update 2 available&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This update also contains newer GCC version including fix newlib nano.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.nxp.com/t5/tag/CMPE200GCC-126/tg-p"&gt;#CMPE200GCC-126&lt;/A&gt;&lt;/P&gt;&lt;P&gt;CMPE200GCC-178&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 28 Aug 2018 08:59:18 GMT</pubDate>
    <dc:creator>alexanderfedoto</dc:creator>
    <dc:date>2018-08-28T08:59:18Z</dc:date>
    <item>
      <title>sprintf bug when using newlib nano with "-u _printf_float" linker option</title>
      <link>https://community.nxp.com/t5/S32-Design-Studio/sprintf-bug-when-using-newlib-nano-with-quot-u-printf-float-quot/m-p/816469#M3686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using S32 Design Studio 2017.R1 for an MPC5777C project. Because of the embedded real-time nature of our project, we are using S32DS newlib nano as the standard "C" library. By default this library does not provide support for sprintf floating point format specifiers, unless "-u _printf_float" is added as a linker command line option.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I added the linker command line option mentioned above, but sprintf() does not work as expected. In my test code the contents of buffer are "&lt;STRONG&gt;nan&lt;/STRONG&gt; xyz", instead of "&lt;STRONG&gt;1.0&lt;/STRONG&gt; xyz" right after the call to sprintf() returns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;int main()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; char buffer [256];&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; sprintf(buffer, "%f xyz", 1.0f);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; counterclass myccounter;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; xcptn_xmpl (); /* Configure and Enable Interrupts */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; /* Loop forever */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; for(;;) { &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; myccounter.increment();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have attached my test project, including the code above, newlib.c (which resolves the missing syscalls that newlib expects), and the compiler/linker settings.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I saw similar behavior in our actual application. In that project I narrowed down the issue to variable _fpvalue getting a value of 0xFFFFFFFFFFFFFFFF in _printf_float (nano-vfprintf_float.c).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;int&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;STRONG&gt;_printf_float&lt;/STRONG&gt; (struct _reent *data,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct _prt_data_t *pdata,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FILE * fp,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int (*pfunc) (struct _reent *, FILE *, _CONST char *,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; size_t len), va_list * ap)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; /* ... */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; if (pdata-&amp;gt;flags &amp;amp; LONGDBL)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _fpvalue = (double) GET_ARG (N, *ap, _LONG_DOUBLE);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; else&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;STRONG&gt;_fpvalue = GET_ARG (N, *ap, double);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* _fpvalue is now 0xFFFFFFFFFFFFFFFF even though argument to sprintf was 1.0f. */&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&amp;nbsp; &amp;nbsp; /* ... */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Has anyone seen this issue and is there a fix for it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Aug 2018 23:37:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-Design-Studio/sprintf-bug-when-using-newlib-nano-with-quot-u-printf-float-quot/m-p/816469#M3686</guid>
      <dc:creator>dan_teodorescu</dc:creator>
      <dc:date>2018-08-22T23:37:31Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf bug when using newlib nano with "-u _printf_float" linker option</title>
      <link>https://community.nxp.com/t5/S32-Design-Studio/sprintf-bug-when-using-newlib-nano-with-quot-u-printf-float-quot/m-p/816470#M3687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;Have you tried to install Update 2 ?&amp;nbsp;&lt;A href="https://community.nxp.com/docs/DOC-340534"&gt;S32 Design Studio for Power Architecture 2017.R1 - Update 2 available&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This update also contains newer GCC version including fix newlib nano.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.nxp.com/t5/tag/CMPE200GCC-126/tg-p"&gt;#CMPE200GCC-126&lt;/A&gt;&lt;/P&gt;&lt;P&gt;CMPE200GCC-178&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Aug 2018 08:59:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-Design-Studio/sprintf-bug-when-using-newlib-nano-with-quot-u-printf-float-quot/m-p/816470#M3687</guid>
      <dc:creator>alexanderfedoto</dc:creator>
      <dc:date>2018-08-28T08:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf bug when using newlib nano with "-u _printf_float" linker option</title>
      <link>https://community.nxp.com/t5/S32-Design-Studio/sprintf-bug-when-using-newlib-nano-with-quot-u-printf-float-quot/m-p/816471#M3688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Alexander,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I upgraded to "S32 Design Studio for Power Architecture 2017.R1 Updates 5 SDK MPC574xx RTM 1.0.0 and Update 6 Service Pack MPC5775x" and I no longer see the issue. Since my configuration excludes dynamic memory allocation, newlib sprintf() cannot generate the textual representation. This is a known limitation of how newlib implements converting floating point values to string. However, the new behavior matches my expectation so this issue can be closed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your support.&lt;/P&gt;&lt;P&gt;Dan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Sep 2018 00:59:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32-Design-Studio/sprintf-bug-when-using-newlib-nano-with-quot-u-printf-float-quot/m-p/816471#M3688</guid>
      <dc:creator>dan_teodorescu</dc:creator>
      <dc:date>2018-09-08T00:59:50Z</dc:date>
    </item>
  </channel>
</rss>

