Skip to content

Error: snprintf is not a member of std #224

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

Closed
dan-ryan opened this issue Mar 16, 2015 · 5 comments
Closed

Error: snprintf is not a member of std #224

dan-ryan opened this issue Mar 16, 2015 · 5 comments

Comments

@dan-ryan
Copy link

I'm getting the error "snprintf is not a member of std" in jsoncpp.cpp, line 3969. I fixed this by removing the "std::". I was using the latest Android NDK.

It might be part of this bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61101

@rpavlik
Copy link

rpavlik commented Mar 16, 2015

Drive by portability comment: for reference, I think visual studio 2005 doesn't have snprintf at all

@dan-ryan
Copy link
Author

for reference, I think visual studio 2005 doesn't have snprintf at all

The code would use "_snprintf" on visual studio.

#if defined(_MSC_VER) && _MSC_VER < 1500 // VC++ 8.0 and below
#define snprintf _snprintf

cdunn2001 pushed a commit to cdunn2001/jsoncpp that referenced this issue Mar 31, 2015
This reverts commit 1c58876.

std::snprintf() is only available in C++11, which is not provided by
all compilers. Since the C library snprintf() can easily be used as a
replacement on Linux systems, this patch changes jsoncpp to use the C
library snprintf() instead of C++11 std::snprintf(), fixing the build error
below:

    src/lib_json/json_writer.cpp:33:18: error: 'snprintf' is not a member of 'std'

See open-source-parsers#231, open-source-parsers#224, and open-source-parsers#218.
@cdunn2001 cdunn2001 mentioned this issue Mar 31, 2015
@cdunn2001
Copy link
Contributor

Your bugzilla link says the problem for that user was a spurious environment variable. Not related, I think.

Yes, snprintf is standard as of C++11. It happens to be available in non-standard ways in previous versions for many compilers. I think the right answer is to use std::snprintf only in the 1.. branch, which officially is intended only for C++11. If we can make it work for earlier versions of C++ too, even better, maybe using #if __cplusplus >= 201103L.

Looking at 1c58876 and #218, I am not happy about the increasing complexity of our snprintf handling. There are exceptions for WINCE and STDC_SECURE, and they are not clearly consistent between files. Let's try to correct this in a better way. I'll look into this more later in the week. For now, #232 should solve your problem. (I included the @baruchsiach commit from #231.)

@oumaymakabiri
Copy link

I'm getting the error: ‘vsnprintf’ is not a member of ‘std’; did you mean ‘vswprintf’?
I didn't quite understand the problem, but I think it's related to the compiler. if anyone can help me solve it please.

@BillyDonahue
Copy link
Contributor

This was solved 8 years ago, wasn't it?
std::vsnprintf is part of C++11, which we require.

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

No branches or pull requests

5 participants