Вопрос

I have a project which uses _vscwprintf()/vswprintf() (via _vsctprintf()/_vstprintf()) to create formatted strings of arbitrary length in malloc()ed buffers.

When I started the project under Visual C++ 2008, _vstprintf() took three parameters:

int vswprintf(wchar_t * _String, const wchar_t * _Format, va_list _Ap)

But after leaving my project for some time when I came back to it with Visual C++ 2012, I've found that MS has changed the function to take four parameters:

int vswprintf(wchar_t * _String, size_t _Count, const wchar_t * _Format, va_list _Ap)

I would like my code to be buildable under Visual C++ 2008, 2010, and 2012 (it's portable to Linux and Solaris too).

Is there some symbol I can check for with #ifdef so that I can build correctly with the 3-parameter or 4-parameter version of the function?

I assume there is a symbol that tells me which version of Visual C++ I'm compiling under, but is this the correct way to do it? For instance is there some possibility that a newer compiler could build with an older C library or runtime, or vice versa?

My code is actually using C rather than C++ if that makes a difference.

Это было полезно?

Решение

As @Roger Rowland said, Due to a bug in Visual studio 2008 http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/b385ed64-d549-4cf3-af31-85a2e8da4b6a/ you should pass 3 arguments in Visual studio 2008 and 4 aguments in newer versions

#ifdef _MSC_VER <= 1500 //Visual Studio 2008 or ealier
// use 3 parameters version here
#else //later than Visual Studio 2008
// use 4 parameters version herse
#endif
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top