说明:移植32到64位 [英] Clarification: Porting 32 to 64 bit

查看:132
本文介绍了说明:移植32到64位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http:引用//msdn.microsoft.com/zh-CN/library/windows/desktop/aa384242%28v=vs.85%29.aspx

在适当的地方使用UINT_PTR和INT_PTR(如果不确定) 无论是否需要它们,仅将它们用于 案子).不要将指针投射到ULONG,LONG,INT,UINT, 或DWORD.

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位代码行中将DWORD的所有引用转换为UNIT_PTR是安全的,没有任何副作用吗?

Can I safely assume that converting all referenced of DWORD to UNIT_PTR in an existing 32 bit Codeline is safe without any side effects?

是否还有其他建议的准则来移植通过代码行引用DWORD的32位代码?

Is there are other recommended guidelines to port a 32 bit code which has referenced to DWORD through out the codeline?

推荐答案

这太粗糙了.只需让编译器为您完成工作,启用警告4302,以便它会在指针值被截断时通知您.将#pragma放在适当的位置,预编译的头文件将是理想的选择.或指定/we4302编译器选项.

This is too crude. Just let the compiler do the work for you, enable warning 4302 so it will tell you when a pointer value gets truncated. Put the #pragma in a good place, the pre-compiled header file would be ideal. Or specify the /we4302 compiler option.

#pragma warning(default:4302)

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

/Wp64编译选项对于嗅探也是有用的,但是它有问题.

The /Wp64 compile option can be useful as well, for a sniff anyway, but it has problems.

这篇关于说明:移植32到64位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆