C++ 将无符号整数转换为无符号字符*

C++ 将无符号整数转换为无符号字符*,c++,c,visual-c++,C++,C,Visual C++,我想得到从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 decla

我想得到从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_地址未获取值0x0a5b0644


我能想出一些办法吗?

从整数类型到指针的转换将由实现定义

如果确实需要无符号整数类型来存储指针,请在
中使用
uintpr\t
(或
intptr\t
用于有符号整数类型)。它们作为可选功能在C++11中引入。它们能够转换为
void*
类型并转换回。

您可以尝试以下操作 假设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
无符号字符字节[11];//字符串中的字符数+null终止符

sprintf(字节,“%#04x”,地址)//它得到了什么值?嗯,这可能是一个有用的情况吗?我得到了一些垃圾值0xFFFF80请说明如何确定
m_Address
作为
0xFFFF80
的值。我怀疑问题就在那里。也许
0xFFFF80
m_address
的地址,而不是它的值?@Griwes:是的。参见C11中的§7.20.1.4(与C99相同)。