其他分享
首页 > 其他分享> > c – 澄清:移植32到64位

c – 澄清:移植32到64位

作者:互联网

引自http://msdn.microsoft.com/en-us/library/windows/desktop/aa384242%28v=vs.85%29.aspx

Use UINT_PTR and INT_PTR where appropriate (and if you are uncertain
whether they are required, there is no harm in using them just in
case). Do not cast your pointers to the types ULONG, LONG, INT, UINT,
or DWORD.

我可以安全地假设在现有的32位Codeline中将所有引用的DWORD转换为UNIT_PTR是安全的,没有任何副作用吗?

是否有其他推荐的指南来移植代码行中引用了DWORD的32位代码?

解决方法:

这太粗糙了.只需让编译器为您完成工作,启用警告4302,这样它就会告诉您指针值何时被截断.把#pragma放在一个好位置,预编译的头文件是理想的.或者指定/ we4302编译器选项.

#pragma warning(default:4302)

int main()
{
    int* p = 0;
    long bad = (long)p;    // C4302: 'type cast' : truncation from int* to long
    return 0;
}

无论如何,/ Wp64编译选项也很有用,但它是has problems.

标签:c,windows,visual-c,porting,dword
来源: https://codeday.me/bug/20190723/1510384.html