joncmu / rapidjson

Automatically exported from code.google.com/p/rapidjson
MIT License
0 stars 0 forks source link

This code in writer.h isn't universal #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This code in writer.h isn't universal:

#if _MSC_VER
        int ret = sprintf_s(buffer, sizeof(buffer), "%g", d);
#else
        int ret = snprintf(buffer, sizeof(buffer), "%g", d);
#endif

I create app for mobile platform with MarmaladeSDK and I have cstdio.h
without sprintf_s, because I work in VisualStudio my project don't build with 
this.

Original issue reported on code.google.com by archj...@gmail.com on 24 Jan 2012 at 6:04

GoogleCodeExporter commented 9 years ago
sprintf_s() is a function provided by Visual C++ 
http://msdn.microsoft.com/en-us/library/ce3zzk1k(v=vs.80).aspx

snprintf() is a C99 standard function that VC does not provide.

What does you platform provide for the same function?

Do you have any suggestion for better compatibly?

Original comment by milo...@gmail.com on 31 Jan 2012 at 7:52

GoogleCodeExporter commented 9 years ago
snprintf() exist on this platform (MarmaladeSDK), but project build with non 
system librares in visual studio (VS compiler for x86; gcc for ARM/MIPS or RVCT 
for ARM) or xcode(gcc).

Simple solution is to create #define like PLATFORM_UNKNOWN with minimal 
functionality (for open source compilers like gcc). User can be set this in 
configuration header file to turn off platforms specific features like 
sprintf_s. 

Please look this example 
http://cocos2d-x.org/projects/cocos2d-x/repository/revisions/master/entry/cocos2
dx/platform/CCPlatformConfig.h - this is multiplatform game engine platform 
detection header.

Original comment by archj...@gmail.com on 31 Jan 2012 at 8:56

GoogleCodeExporter commented 9 years ago
This issue won't be fixed recently.
In future, I will try to abstract most functions like this, and may provide 
custom number to string converter internally to remove the dependency on 
snprintf().

Original comment by milo...@gmail.com on 19 Feb 2012 at 3:47