Errors, Help!!!  
Author Message
Lejing





PostPosted: Visual C++ General, Errors, Help!!! Top

When I try to include string like:

#include <string>

I always got following errors:

E:\MicrosoftVisualStudio8\VC\include\cstdio(37) : error C2039: 'Unsafe_sprintf' : is not a member of '`global namespace''
E:\MicrosoftVisualStudio8\VC\include\cstdio(37) : error C2873: 'Unsafe_sprintf' : symbol cannot be used in a using-declaration
E:\MicrosoftVisualStudio8\VC\include\cstring(20) : error C2039: 'Unsafe_strcat' : is not a member of '`global namespace''
E:\MicrosoftVisualStudio8\VC\include\cstring(20) : error C2873: 'Unsafe_strcat' : symbol cannot be used in a using-declaration
E:\MicrosoftVisualStudio8\VC\include\cstring(21) : error C2039: 'Unsafe_strcpy' : is not a member of '`global namespace''
E:\MicrosoftVisualStudio8\VC\include\cstring(21) : error C2873: 'Unsafe_strcpy' : symbol cannot be used in a using-declaration
E:\MicrosoftVisualStudio8\VC\include\cwchar(34) : error C2039: 'Unsafe_swprintf' : is not a member of '`global namespace''
E:\MicrosoftVisualStudio8\VC\include\cwchar(34) : error C2873: 'Unsafe_swprintf' : symbol cannot be used in a using-declaration
E:\MicrosoftVisualStudio8\VC\include\cwchar(37) : error C2039: 'Unsafe_wcscat' : is not a member of '`global namespace''
E:\MicrosoftVisualStudio8\VC\include\cwchar(37) : error C2873: 'Unsafe_wcscat' : symbol cannot be used in a using-declaration
E:\MicrosoftVisualStudio8\VC\include\cwchar(39) : error C2039: 'Unsafe_wcscpy' : is not a member of '`global namespace''
E:\MicrosoftVisualStudio8\VC\include\cwchar(39) : error C2873: 'Unsafe_wcscpy' : symbol cannot be used in a using-declaration



Visual C++12  
 
 
Mike Danes





PostPosted: Visual C++ General, Errors, Help!!! Top

Are you including something else before <string> Do you have any #defines

I cannot find any trace of 'Unsafe_' in the Visual C++ header files so I suspect it comes from another place.


 
 
Lejing





PostPosted: Visual C++ General, Errors, Help!!! Top

Thank you first!

Actually, I copy the code from some places, and want to reuse a part of them, so I do not know the details. Is there any possibility I can solve it Could you give me some hints Thank you again!

 
 
Holger Grund





PostPosted: Visual C++ General, Errors, Help!!! Top

I guess, it's some kind of bad macro definition. You can preprocess the source file with line numbers and search the resulting output file for the offending identifiers (such as Unsafe_sprintf). You can probably reconstruct which identifier is defined as a macro by comparing the line in the original source file and the line in the preprocessed file. I'd bet it is sprintf in your case. Do you define this macro at the command line If so, you are not supposed to - it's undefined behavior. Otherwise just #define it to itself (e.g. /Dsprintf=sprintf) and recompile. When the compiler sees a different #define sprintf xyz it should drop a warning macro redefinition and point you to the offending line of source code.

-hg


 
 
Simple Samples





PostPosted: Visual C++ General, Errors, Help!!! Top

Probably there is a header missing and to find it, just search the headers in the original project for "Unsafe_sprintf" and the others. Then you can either use the header as-is or make another version of the header for your use that only contains the parts you need.

Another possibility, if possible, is to replace all occurences of symbols that begin with Unsafe_ with a safe equivalent. I assume, but I cannot be sure, that the reason the prefix Unsafe_ is used is so that occurences of unsafe code can be easily found. It is highly likely that there was/is an intent to replace the unsafe code, so your reuse of the code (depending on how it is reused) is a productive time to do that in the code you are reusing.