开发者

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 ?


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


Changing option Treat wchar_t as native type to NO worked for me :). VC++ 2010 express.


You'll probably be fine but, if it were me, I'd do a search and replace and change references to Unicode characters to wchar_t. For starters, you might just make your code work with future changes to the libraries. It would also make your code easier to read.

Unless I'm missing something, mbstowcs and wcstombs have nothing to do with this. They are for converting between Unicode and multiple. It sounds like all your stuff is Unicode.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜