简体   繁体   中英

Type cast warning from DWORD to 64 bit pointer

An old 32 bit C++ application (MS Visual Studio) has code lines like this:

m_value = (PUCHAR)someDWORD;

Where PUCHAR is a pointer to an unsigned char.

Now I have changed to 64 bit and I get a (valid) warning about conversion from DWORD to the 64 bit pointer. My unqualified solution to this is to write like this:

m_value = (PUCHAR)(DWARD_PTR)someDWORD;

Is this the correct way to fix this warning (and potential runtime error)?

That savage cast to DWORD_PTR will only pad someDWORD with zeros, it won't bring back the upper half of the pointer value that was lost.

You need someDWORD to be a DWORD_PTR (or, in fact, a std::uintptr_t ) from the beginning.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM