Sprintf () bug under ARM-GCC?

Source: Internet
Author: User

Debugging todayProgram, FoundARM-GCCLowerSprintf ()It does not support floating point numbers. I have never encountered this problem before, and I think it will certainly not be a problem.Adl_user_guide.ARM-GCCUnderSprintf ()Not Supported% FThe document provides the corresponding solution.

Important remark about GCC compiler:

When using GCC compiler, due to internal standard C Library Architecture, it is stronugly not recommended to use the "% F" mode in the wm_sprintf function in order to convert a float variable to a string. this leads to an arm exception (product reset ).

A way around for this conversion is:

Float myfloat; // float to display

ASCII mystring [100]; // destination string

S16 D, F;

D = (S16) myfloat * 1000; // decimal precision: 3 digits

F = (myfloat * 1000)-D; // decimal precision: 3 digits

Wm_sprintf (mystring, "% d. % 03d", (S16) myfloat, f); // decimal precision: 3 digits

Practice has proved that it is important to read documents rather than experience.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.