Search code examples
visual-c++visual-studio-2005visual-studio-6

Is it safe to typecast unsigned short to wchar_t and vise versa?


Hello I am migrating project from Visual studio 6.0 to Visual Studio 2005.

The problem i am facing is ths ... in VS 6.0 wchar_t was simply typecast of unsigned short but in VS2005 wchar_t is built in data type.

In project previous programmers have used wchar_t and unsigned short intechangibally. But in Vs 2005 it showing errors like cannot convert from wchar_t to unsigned short and vise versa.

So my question is can we safely cast wchar_t to unsigned short and vise versa or we need use functions like mbstowcs and wcstombs ?


Solution

  • You can use the /Zc:wchar_t- (or its equivalent in the project settings dialog) to turn off the wchar_t-as-native-type feature in VS 2005:

    http://msdn.microsoft.com/en-us/library/dh8che7s%28v=vs.80%29.aspx