<?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>8-bit Microcontrollers中的主题 Re: sprintf, snprintf and floating point</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197195#M15858</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What you're saying makes sense so I took a look at the options as they are in the README.TXT file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;C   IEEE32/32 banked  HCS08 with MMU      ansibfm.lib  -W2 -Os -cs08 -MMU -Mt -Fd             -F2 -NoPath
C   IEEE32/64 banked  HCS08 with MMU      ansibm.lib   -W2 -Os -cs08 -MMU -Mt                 -F2 -NoPath
C   Integral only banked  HCS08 with MMU  ansibim.lib  -W2 -Os -cs08 -MMU -Mt -D__NO_FLOAT__  -F2 -NoPath
C++ IEEE32/32 banked  HCS08 with MMU      cppbfm.lib   -W2 -Os -cs08 -MMU -Mt -Fd             -F2 -NoPath
C++ IEEE32/64 banked  HCS08 with MMU      cppbm.lib    -W2 -Os -cs08 -MMU -Mt                 -F2 -NoPath
C++ Integral only banked  HCS08 with MMU  cppbim.lib   -W2 -Os -cs08 -MMU -Mt -D__NO_FLOAT__  -F2 -NoPath
               

Integral only libraries do not contain floating point operations.

Options used:
-W2:     Suppress warning and information messages
-Os:     Optimize for code size
-cs08:   Generate code for HCS08
-MMU:    Enable MMU support
-Ms:     Small memory model
-Mt:     tiny memory model
-Mb:     Banked memory model
-Fd:     Float and double is IEEE32
-F2:     ELF/DWARF 2.0
-NoPath: Do not write path information into object files
(for more details, see the provided online documentation)
&lt;/PRE&gt;&lt;P&gt;I'm currently using ansibm.lib and as you can see, there is no ansibm.lib with a -Mb option for banked so I can't get one with the memory model as you suggested.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The compiler options I'm currently using are:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Cs08 -Mb -MMU -TD2LD2LLD2 -WmsgSd4301 -WmsgSd5703&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so, the memory model is banked and there is no -Fd which matches the options (with the exception of the memory model) in README.TXT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried float and double -- both give 50.124 in sprintf().&amp;nbsp; Also, formats %f and %lf don't make any difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll try the wizard created project next.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 04 May 2010 20:06:37 GMT</pubDate>
    <dc:creator>JBM</dc:creator>
    <dc:date>2010-05-04T20:06:37Z</dc:date>
    <item>
      <title>sprintf, snprintf and floating point</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197187#M15850</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I know this has been discussed many times and I have read the posts with no luck.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working with an MC9S08QE128.h with Codewarrior (version 5.9 and compiler version 5.0.14).&amp;nbsp; I'm trying to get sprintf to format&amp;nbsp; a floating point and not having any luck.&amp;nbsp; I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(1) Checked in libdefs.h that LIBDEF_PRINTF_FLOATING is 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;(2) I'm using the banked memory model and have include the ANSIBM.A library (float = double = 32 bits)&lt;/P&gt;&lt;P&gt;(3) Gone through all compiler options, "Double is IEEE32" is checked.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there something else required?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, where is snprintf()?&amp;nbsp; I don't normally use sprintf because of overflow issues, but snprintf() doesn't seem be where it's supposed to be (stdio).&amp;nbsp; The help file says it's there, but a search of stdio.h, does not show a prototype and the linker fails because the symbol "snprintf" is not defined which tells me the code doesn't exist.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Brad&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 May 2010 06:49:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197187#M15850</guid>
      <dc:creator>JBM</dc:creator>
      <dc:date>2010-05-03T06:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf, snprintf and floating point</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197188#M15851</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I also tried the ANSIBFM.LIB (float is 32 bits, double is 64) and got the same results.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 May 2010 07:41:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197188#M15851</guid>
      <dc:creator>JBM</dc:creator>
      <dc:date>2010-05-03T07:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf, snprintf and floating point</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197189#M15852</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;snprintf is in C99. Codewarrior implements C90.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;C99 = ISO 9899:1999.&lt;/P&gt;&lt;P&gt;C90 = ANSI/ISO 9899:1900.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Very few, if any, embedded compilers implement C99.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 May 2010 19:44:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197189#M15852</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2010-05-03T19:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf, snprintf and floating point</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197190#M15853</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just thought it was odd that the documentation says it's there and it's not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas on getting sprintf to work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Brad&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 May 2010 21:28:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197190#M15853</guid>
      <dc:creator>JBM</dc:creator>
      <dc:date>2010-05-03T21:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf, snprintf and floating point</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197191#M15854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;- I don't know a "ANSIBM.A" library, use&amp;nbsp;ansibfm.lib when using the banked memory model with -cf (IEEE32 for both float/double), see the readme.txt in lib/hc08c.&lt;/P&gt;&lt;P&gt;- Make sure that you have enough stack space, not sure if the default is sufficient.&lt;/P&gt;&lt;P&gt;- Also, how is it failing for you?&lt;/P&gt;&lt;P&gt;- the macro&amp;nbsp;LIBDEF_PRINTF_FLOATING is considered when building the library, so if you use a stock library changing it wont help.&lt;/P&gt;&lt;P&gt;- I think I did provide some snprintf implementation in the forum once, basically the base code provides a call back which can be used to implement the boundary checking for snprintf too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 May 2010 03:23:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197191#M15854</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2010-05-04T03:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf, snprintf and floating point</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197192#M15855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;See&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.freescale.com/message/17411#17411" title="https://community.freescale.com/message/17411#17411"&gt;https://community.freescale.com/message/17411#17411&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 May 2010 03:29:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197192#M15855</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2010-05-04T03:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf, snprintf and floating point</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197193#M15856</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for replying.&amp;nbsp; I've tried both ANSIBM.LIB and ANSIBFM.LIB with float an double arguments.&amp;nbsp; What I'm getting is the wrong float converted to a string such as "50.124" for M_PI.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 May 2010 05:28:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197193#M15856</guid>
      <dc:creator>JBM</dc:creator>
      <dc:date>2010-05-04T05:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf, snprintf and floating point</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197194#M15857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;nbsp;"50.124" &amp;nbsp;means that the floating point format you tell the compiler to use (with -cf, type option dialog) does not match the&amp;nbsp;setting of the used library.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please create a project with the wizard with the settings you want (increase the stack space, not sure if default is big enough) and see what you get there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Check this web page:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://babbage.cs.qc.edu/IEEE-754/Decimal.html" rel="nofollow" target="_self"&gt;http://babbage.cs.qc.edu/IEEE-754/Decimal.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;50.124 in IEEE64 is 0x40490FDF3B645A1D&lt;/P&gt;&lt;P&gt;PI as IEEE32 is is 0x40490FDB.&lt;/P&gt;&lt;P&gt;Note the identical leading digits, is appears that in your setup the compiler is using IEEE32 but a IEEE64 bit library is used. The readme.txt in lib/hc08c contains the options used to build the library. The floating point options you use (and the memory model) should match the ones used there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 May 2010 09:16:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197194#M15857</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2010-05-04T09:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf, snprintf and floating point</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197195#M15858</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What you're saying makes sense so I took a look at the options as they are in the README.TXT file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;C   IEEE32/32 banked  HCS08 with MMU      ansibfm.lib  -W2 -Os -cs08 -MMU -Mt -Fd             -F2 -NoPath
C   IEEE32/64 banked  HCS08 with MMU      ansibm.lib   -W2 -Os -cs08 -MMU -Mt                 -F2 -NoPath
C   Integral only banked  HCS08 with MMU  ansibim.lib  -W2 -Os -cs08 -MMU -Mt -D__NO_FLOAT__  -F2 -NoPath
C++ IEEE32/32 banked  HCS08 with MMU      cppbfm.lib   -W2 -Os -cs08 -MMU -Mt -Fd             -F2 -NoPath
C++ IEEE32/64 banked  HCS08 with MMU      cppbm.lib    -W2 -Os -cs08 -MMU -Mt                 -F2 -NoPath
C++ Integral only banked  HCS08 with MMU  cppbim.lib   -W2 -Os -cs08 -MMU -Mt -D__NO_FLOAT__  -F2 -NoPath
               

Integral only libraries do not contain floating point operations.

Options used:
-W2:     Suppress warning and information messages
-Os:     Optimize for code size
-cs08:   Generate code for HCS08
-MMU:    Enable MMU support
-Ms:     Small memory model
-Mt:     tiny memory model
-Mb:     Banked memory model
-Fd:     Float and double is IEEE32
-F2:     ELF/DWARF 2.0
-NoPath: Do not write path information into object files
(for more details, see the provided online documentation)
&lt;/PRE&gt;&lt;P&gt;I'm currently using ansibm.lib and as you can see, there is no ansibm.lib with a -Mb option for banked so I can't get one with the memory model as you suggested.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The compiler options I'm currently using are:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Cs08 -Mb -MMU -TD2LD2LLD2 -WmsgSd4301 -WmsgSd5703&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so, the memory model is banked and there is no -Fd which matches the options (with the exception of the memory model) in README.TXT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried float and double -- both give 50.124 in sprintf().&amp;nbsp; Also, formats %f and %lf don't make any difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll try the wizard created project next.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 May 2010 20:06:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197195#M15858</guid>
      <dc:creator>JBM</dc:creator>
      <dc:date>2010-05-04T20:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf, snprintf and floating point</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197196#M15859</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I created the project with the wizard and it works.&amp;nbsp; The compiler options were -Cs08 -MMU -Mb.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried to find what option was giving the -TD2LD2LLD2. option.&amp;nbsp; I selected each option in the listbox (didn't check it, just selected it) and without changing any options, that compiler option disappeared and now my code works.&amp;nbsp; Any ideas what caused that?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 May 2010 20:29:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197196#M15859</guid>
      <dc:creator>JBM</dc:creator>
      <dc:date>2010-05-04T20:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf, snprintf and floating point</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197197#M15860</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The readme.txt contains one bug, the option for the memory model options for the banked libraries is -mb, not -mt as it states.&lt;/P&gt;&lt;P&gt;-Fd is equivalent to&amp;nbsp; -TD2LD2LLD2, in fact when I added -Fd in the GUI, the&amp;nbsp; -TD2LD2LLD2 got automatically added for me.&lt;/P&gt;&lt;P&gt;So if you want to use IEEE32 for double, use ansibfm.lib (note the f).&lt;/P&gt;&lt;P&gt;If you want to use IEEE64, drop the -TD2LD2LLD2 in the command line.&lt;/P&gt;&lt;P&gt;In ANSI-C, floats are promoted to double for function calls with the ellipsis notation, like sprintf, so there is no way to pass a float to sprintf, it always passes a double.&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>Tue, 04 May 2010 20:42:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197197#M15860</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2010-05-04T20:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf, snprintf and floating point</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197198#M15861</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No, if you are able to reproduce I would suggest to file a service request for the next person,&lt;/P&gt;&lt;P&gt;just selecting options without checking/unchecking any should not change the existing options.&lt;/P&gt;&lt;P&gt;For&amp;nbsp;-TD2LD2LLD2 note that -cf has the same meaning, so checking/unchecking -cf can affect the -T option.&lt;/P&gt;&lt;P&gt;Anyway, sounds like a separate issue.&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>Wed, 05 May 2010 02:30:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/sprintf-snprintf-and-floating-point/m-p/197198#M15861</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2010-05-05T02:30:16Z</dc:date>
    </item>
  </channel>
</rss>

