Problem with snprintf()

mmonsterski
Wed Mar 08, 2017 12:16 pm
Hello
I’m trying to port code from Arduino Uno to Bluepill but I have problem with snprintf(). When I’m compiling code I have error:

test_snprintf:9: error: 'snprintf' was not declared in this scope


stevestrong
Wed Mar 08, 2017 1:00 pm
Search the forum (top right field on the page) for “sprintf”.

mmonsterski
Wed Mar 08, 2017 1:16 pm
I know that sprintf() is included but in this specific application I want to use safer snprintf(). That’s why I’m asking about this function.

Rick Kimball
Wed Mar 08, 2017 3:08 pm
try:

#include <cstdio>

… someplace at the top of the your code


mmonsterski
Thu Mar 09, 2017 7:55 am
Include <cstdio> just give compiler error.

I’ve found solution:
viewtopic.php?f=3&t=1241
In stdio.h snprintf in in preprocessor if:
#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L)
[...] int _EXFUN(snprintf, (char *__restrict, size_t, const char *__restrict, ...)
_ATTRIBUTE ((__format__ (__printf__, 3, 4))));
[...] #endif /* !__STRICT_ANSI__ */


RogerClark
Thu Mar 09, 2017 8:46 pm
Interesting…

There is a separate thread where we are testing whether adding. -std=gnu++11. causes any problems.

But we had not considered also adding -std=gnu11 for C files.


mmonsterski
Fri Mar 10, 2017 7:05 am
I found that because example project using snprintf() compile successfully at Arduino Due. After reading stdio.h and http://stackoverflow.com/questions/5580 … -get-along and little investigation I’ve found at platform.txt for Due:
compiler.c.flags=[...] -std=gnu11 [...] compiler.cpp.flags=[...] -std=gnu++11 [...]

RogerClark
Fri Mar 10, 2017 9:13 am
OK

The plan is to add both the C and C++ flags

I hope to update the repo this weekend


BennehBoy
Fri Mar 10, 2017 10:00 am
RogerClark wrote:
I hope to update the repo this weekend

RogerClark
Fri Mar 10, 2017 8:41 pm
I will need to look at the list if PRs that are pending.

There are some PRs which I will never action,because they solve a problem for one individual but break things for everyone else.

I know there is @stevstrong’s SPI PR but it slows down the SPI, last time I tried it, and speed decreases usually dont go down well with users even though there is a valid bug fix that causes the slowdown.

But as Victor is currently working on improved DMA for SPU, I was going to wait and do all the SPI changes at the same time.

So its likely I will only change the compiler switches and change to using nanolib at the weekend


BennehBoy
Fri Mar 10, 2017 9:23 pm
NP, I was just wondering if I could expect anything else to change.

Do you usually update a change record?


Leave a Reply

Your email address will not be published. Required fields are marked *