<?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 Format (printf, scanf) warning do not appear. -Wformat not respected? in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/Format-printf-scanf-warning-do-not-appear-Wformat-not-respected/m-p/1235189#M44001</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm using&amp;nbsp;demo code from&amp;nbsp;MCUXpresso SDK 2.9.0 to&amp;nbsp;compile a "bare-metal" program for an ARM Cortex-M33 based microcontroller (specifically, the LPC55S28 but this should be irrelevant to the question).&lt;/P&gt;&lt;P&gt;I added this example code to the &lt;FONT face="andale mono,times"&gt;main()&lt;/FONT&gt; function (and the relevant include):&lt;/P&gt;&lt;PRE&gt;double f = 1.0;&lt;BR /&gt;printf("%i\n", f);&lt;/PRE&gt;&lt;P&gt;Compiling this code should give a warning as the format '%i' expects argument of type 'int', but&amp;nbsp;variable f has type 'double'. The warning is based on the compiler option "-Wformat" that is enabled by option "-Wall" (which is enabled by default for this project).&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;However, no format warning appears.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I wonder how this can be fixed?&amp;nbsp;I find the warning messages very helpful.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I checked the compiler call for compiling this source file and when I remove the option "-specs=redlib.specs" from it, the warning message appears.&lt;/P&gt;&lt;P&gt;Is the "-specs" option required, what does it do and why does it inhibit "-Wformat"?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;Dan&lt;/P&gt;</description>
    <pubDate>Tue, 23 Feb 2021 19:34:11 GMT</pubDate>
    <dc:creator>danielholala</dc:creator>
    <dc:date>2021-02-23T19:34:11Z</dc:date>
    <item>
      <title>Format (printf, scanf) warning do not appear. -Wformat not respected?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Format-printf-scanf-warning-do-not-appear-Wformat-not-respected/m-p/1235189#M44001</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm using&amp;nbsp;demo code from&amp;nbsp;MCUXpresso SDK 2.9.0 to&amp;nbsp;compile a "bare-metal" program for an ARM Cortex-M33 based microcontroller (specifically, the LPC55S28 but this should be irrelevant to the question).&lt;/P&gt;&lt;P&gt;I added this example code to the &lt;FONT face="andale mono,times"&gt;main()&lt;/FONT&gt; function (and the relevant include):&lt;/P&gt;&lt;PRE&gt;double f = 1.0;&lt;BR /&gt;printf("%i\n", f);&lt;/PRE&gt;&lt;P&gt;Compiling this code should give a warning as the format '%i' expects argument of type 'int', but&amp;nbsp;variable f has type 'double'. The warning is based on the compiler option "-Wformat" that is enabled by option "-Wall" (which is enabled by default for this project).&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;However, no format warning appears.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I wonder how this can be fixed?&amp;nbsp;I find the warning messages very helpful.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I checked the compiler call for compiling this source file and when I remove the option "-specs=redlib.specs" from it, the warning message appears.&lt;/P&gt;&lt;P&gt;Is the "-specs" option required, what does it do and why does it inhibit "-Wformat"?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;Dan&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 19:34:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Format-printf-scanf-warning-do-not-appear-Wformat-not-respected/m-p/1235189#M44001</guid>
      <dc:creator>danielholala</dc:creator>
      <dc:date>2021-02-23T19:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: Format (printf, scanf) warning do not appear. -Wformat not respected?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Format-printf-scanf-warning-do-not-appear-Wformat-not-respected/m-p/1235216#M44003</link>
      <description>&lt;P&gt;Suggest you switch to newlib...&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.nxp.com/t5/LPCXpresso-IDE-FAQs/What-are-Redlib-and-Newlib/m-p/475288" target="_blank"&gt;https://community.nxp.com/t5/LPCXpresso-IDE-FAQs/What-are-Redlib-and-Newlib/m-p/475288&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 21:07:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Format-printf-scanf-warning-do-not-appear-Wformat-not-respected/m-p/1235216#M44003</guid>
      <dc:creator>converse</dc:creator>
      <dc:date>2021-02-23T21:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: Format (printf, scanf) warnings do not appear. -Wformat not respected?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Format-printf-scanf-warning-do-not-appear-Wformat-not-respected/m-p/1236594#M44041</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/144226"&gt;@converse&lt;/a&gt;&amp;nbsp;, thanks for suggesting to switch to newlib.&amp;nbsp;&lt;/P&gt;&lt;P&gt;To try your suggestion, I switched the project to newlib using "Quicksettings".&lt;/P&gt;&lt;P&gt;Using newlib, the warning message appears as expected.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, now the compiler emits a warning regarding the following lines:&lt;/P&gt;&lt;PRE&gt;uint32_t i = 0;&lt;BR /&gt;printf("%u\n", i);&lt;/PRE&gt;&lt;P&gt;The warning reads&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="andale mono,times"&gt;warning: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'uint32_t' {aka 'long unsigned int'} [-Wformat=]&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Obviously, with switching to newlib a different &lt;FONT face="andale mono,times"&gt;stdint.h&lt;/FONT&gt;&amp;nbsp;header file has been included. Using newlib, &lt;FONT face="andale mono,times"&gt;uint32_t&lt;/FONT&gt; is now defined as &lt;FONT face="andale mono,times"&gt;long unsigned int&lt;/FONT&gt;.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;In comparison, Redlib defines &lt;FONT face="andale mono,times"&gt;uint32_t&lt;/FONT&gt; as &lt;FONT face="andale mono,times"&gt;unsigned int&lt;/FONT&gt;.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;To fix this, I'll have to adapt all format strings accordingly. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Anything else important that the change to newlib brings along?&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 12:06:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Format-printf-scanf-warning-do-not-appear-Wformat-not-respected/m-p/1236594#M44041</guid>
      <dc:creator>danielholala</dc:creator>
      <dc:date>2021-02-25T12:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: Format (printf, scanf) warnings do not appear. -Wformat not respected?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Format-printf-scanf-warning-do-not-appear-Wformat-not-respected/m-p/1236597#M44042</link>
      <description>&lt;P&gt;Suggest you read this:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.nxp.com/t5/LPCXpresso-IDE-FAQs/What-are-Redlib-and-Newlib/m-p/475288" target="_blank"&gt;https://community.nxp.com/t5/LPCXpresso-IDE-FAQs/What-are-Redlib-and-Newlib/m-p/475288&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Basically, redlib is a cut-down C90 library to try to minimise the size of the library (with a few C99 features). Newlib (and it's smaller variant newlib-nano) are based on C99 (and later) so are compliant with more modern C standards.&lt;/P&gt;&lt;P&gt;If you are trying to follow modern standard, you should use newlib.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 12:24:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Format-printf-scanf-warning-do-not-appear-Wformat-not-respected/m-p/1236597#M44042</guid>
      <dc:creator>converse</dc:creator>
      <dc:date>2021-02-25T12:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: Format (printf, scanf) warnings do not appear. -Wformat not respected?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Format-printf-scanf-warning-do-not-appear-Wformat-not-respected/m-p/1236649#M44044</link>
      <description>&lt;P&gt;Dear &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/144226"&gt;@converse&lt;/a&gt; , of course I've read the page you linked to. While I'm not using a lot of libc functions, I'd like to use and follow a modern C standard. I always use the &amp;lt;stdint.h&amp;gt; and &amp;lt;stdbool.h&amp;gt; headers which are C99 but they are also provided by Redlib.&lt;/P&gt;&lt;P&gt;I'm confused why suddenly gcc warns about the incompatibility of format "%u" and uint32_t type argument.&lt;/P&gt;&lt;P&gt;When I compile the code using, e.g., gcc 9.3.0 (Ubuntu via WSL) I don't get this warning.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 14:12:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Format-printf-scanf-warning-do-not-appear-Wformat-not-respected/m-p/1236649#M44044</guid>
      <dc:creator>danielholala</dc:creator>
      <dc:date>2021-02-25T14:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: Format (printf, scanf) warnings do not appear. -Wformat not respected?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Format-printf-scanf-warning-do-not-appear-Wformat-not-respected/m-p/1236758#M44045</link>
      <description>&lt;P&gt;Its because there is no guarantee that format specifiers will match the definition across platforms. You will need to use %ul in LPCXpresso and %u on Ubuntu.&lt;/P&gt;&lt;P&gt;The only way to guarantee this is to use&amp;nbsp;the format specifier macros - which looks ugly and unreadable, but avoids errors...&lt;/P&gt;&lt;PRE&gt;#include &amp;lt;inttypes.h&amp;gt;&lt;BR /&gt;&lt;BR /&gt;uint32_t value;&lt;BR /&gt;&lt;BR /&gt;printf("%"PRIu32"\n", value) ;&lt;/PRE&gt;&lt;P&gt;See&amp;nbsp;&lt;A href="https://en.cppreference.com/w/c/types/integer" target="_blank"&gt;https://en.cppreference.com/w/c/types/integer&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and look for "format macro constants"&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 17:10:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Format-printf-scanf-warning-do-not-appear-Wformat-not-respected/m-p/1236758#M44045</guid>
      <dc:creator>converse</dc:creator>
      <dc:date>2021-02-25T17:10:53Z</dc:date>
    </item>
  </channel>
</rss>

