[Solved]across platform
-
Hi guys, please me out
If I wanna make the following expression run on window and ubuntu, what is the better way to do, or the below is good enough:
@for(int i=sym.count(); i > 0; i -=4)
{
num = (((num << 5) + num) + (num >> 27));
if( i <= 2)
{
break;
}
num2 = (((num2 << 5) + num2) + (num2 >> 27));
}
}qint32 key = (num + (num2 * 1566083941));@
-
How does this have anything to do with portability between Windows and Ubuntu? It's pretty straightforward C++ code. The only remotely Qt-related code is the quint32.
I'm not really sure what aspect of the you're questioning.
(It doesn't even seem to be a complete snippet of code. Mismatched braces.)
-
yes, you are right, my problem is :running my app is good on win7,getHashCode()is ok, but when I run the same app on ubuntu, getHashCode() generate a wrong value.I suspect that the error is from the integal type. the following is the relating code
@qint32 neoseis::getMyStringHashCode(const QString& sym)
{
qint32 num = 352654597;
wchar_t *warray = new wchar_t[c+1];
sym.toWCharArray(warray);
delete []warray;
return key;
}@ -
Why use wchar_t width of which is dependent on platform?
-
BTW: Are you sure that "running my app is good on win7"
@
wchar_t warray = new wchar_t[c+1];
//...
int numPtr = (int*) warray;
@IMO, such codes perhaps work under some linux system, but will not work correctly under Windows.
-
Keep in mind that:
The width of wchar_t is compiler-specific and can be as small as 8 bits. Consequently, programs that need to be portable across any C or C++ compiler should not use wchar_t for storing Unicode text. The wchar_t type is intended for storing compiler-defined wide characters, which may be Unicode characters in some compilers.
If you use Qt, why not go with QString all the way and avoid portability issues?