0

我想从 unsigned int 获取值到 unsigned char *,我的逻辑给出了错误的值

unsigned int Address = 0x0a5b0644; // this value is getting ss fun parameter
m_Address        = (unsigned char*)Address;  // this logic wrote in side C++ file

unsigned char * m_Address; // this is declared inside H file

这里 m_Address 没有得到值 0x0a5b0644

我能想出一些主意吗

4

2 回答 2

2

从整数类型转换为指针将由实现定义。

uintptr_t如果您确实需要无符号整数类型来存储指针,intptr_t请在<cstdint>. 它们在C++11中作为可选功能引入。它们能够转换为void *类型并转换回来。

于 2013-06-28T14:49:50.183 回答
0

您可以尝试以下假设 unsigned int 是 4 个字节,{0x0a, 0x5b, 0x06, 0x44}

unsigned char bytes[11];// the number of charactoer in the string + a null terminating
sprintf(bytes, "%#04x", Address); //<here it will print it
于 2013-06-28T16:24:45.800 回答