cancel
Showing results for 
Search instead for 
Did you mean: 

The sprint function prints 0

MDuga
Associate

0690X000008BfjwQAC.jpg

3 REPLIES 3

Yes, so you're linking a limited capability library not supporting floating point printf/scanf functionality. Build with the proper library/settings. Similar issues with other GNU/GCC / TrueStudio based tools, search the forum, covered a shed load of times.

Or, just use some professional tools like Keil or IAR where things predominantly just work properly without having to read the documentation.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
MDuga
Associate

You can give a link to the forum on this topic?

Not the GP, try to search the web for "_printf_float". Here's a couple of links.

Your toolchain uses a free "Standard C" library called "newlib". More precisely, it uses the subset of the library called "newlib-nano" which is designed for memory/flash-constrained devices. If you read its documentation [1, 2] (yes, it's ok for professionals to read the documentation of the tools/libraries they use) you can find this:

Floating-point support is split out of the formatted I/O code into

weak functions which are not linked by default. Programs that need

floating-point I/O support must explicitly request linking of one or

both of the floating-point functions: _printf_float or _scanf_float.

This can be done at link time using the -u option which can be passed

to either gcc or ld. The -u option forces the link to resolve those

function references. Floating-point format specifiers are recognized

by default, but if the floating-point functions are not explicitly

linked in, this may result in undefined behavior for programs that

need floating-point I/O support.