Skip to content

std::snprintf not part of std for MinGW32 using c++11 #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 6, 2016

Conversation

magnific0
Copy link
Contributor

Unfortunately MinGW32 (GCC 4.8.1-4) refuses to bulid jsoncpp. Giving the following error:

jsoncpp\src\lib_json\json_reader.cpp:33:18: error: 'snprintf' is not a member of 'std'
   #define snprintf std::snprintf

This issue has been covered before (#231 and #244). Although this is most likely a bug in MinGW32, but as the project is inactive (and it is still shipped with the Windows build of QtCreator), I propose to add the following if clause here. If MinGW32 is detected std::snprintf is not used, but simply the old C library snprintf instead.

@BillyDonahue
Copy link
Contributor

It's surprising that the #define line is being checked for validity. I don't get that.

Are we even using snprintf for anything in those files?
https://github.com/open-source-parsers/jsoncpp/search?utf8=%E2%9C%93&q=snprintf
I think it would be smart to just remove the #define if it's unused.

If we need standard float formatting, we can probably get it more portably out of the ostream library.

@magnific0
Copy link
Contributor Author

Hi @BillyDonahue, thanks for the quick reply. As you say snprintf is unused in the two files that caused me problems. I did not remove the definitions as I do not presume to know their purpose. Removing them will be an equably agreeable solution. I will update my pull request shortly!

@BillyDonahue
Copy link
Contributor

The only way the macros could affect you is if the token 'snprintf' is used in the expansion of a macro defined in one of the headers. But it isn't, so you're good.

@cdunn2001
Copy link
Contributor

$ git grep -n snprintf
src/lib_json/json_reader.cpp:24:#define snprintf sprintf_s
src/lib_json/json_reader.cpp:26:#define snprintf std::snprintf
src/lib_json/json_reader.cpp:28:#define snprintf _snprintf
src/lib_json/json_reader.cpp:31:#define snprintf snprintf
src/lib_json/json_reader.cpp:33:#define snprintf std::snprintf
src/lib_json/json_reader.cpp:813:  snprintf(buffer, sizeof(buffer), "Line %d, Col
src/lib_json/json_reader.cpp:1817:  snprintf(buffer, sizeof(buffer), "Line %d, Co
...

snprintf is used there. I don't know why the github search does not see it. Oh, I see:

Showing the top six matches. Last indexed on Oct 27, 2015.

cdunn2001 added a commit that referenced this pull request Feb 6, 2016
std::snprintf not part of std for MinGW32 using c++11
@cdunn2001 cdunn2001 merged commit 2c872ec into open-source-parsers:master Feb 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants