如何将指定的类型指针强制转换为整数? [英] How to cast an specified type pointer to integer?
问题描述
我想将地址打包到字节缓冲区。所以我需要将其转换为
整数值。
如何投出它?
const char * ptr = 0x0013e328;
int value =< cast(ptr); //使用reinterpret_cast?
I want to package an address to byte buffer. So I need to cast it to
integer value.
How to cast it?
const char * ptr = 0x0013e328;
int value = <cast(ptr); // use reinterpret_cast?
推荐答案
Allen写道:
Allen wrote:
I想要将地址打包到字节缓冲区。所以我需要将它转换为
整数值。
I want to package an address to byte buffer. So I need to cast it to
integer value.
为什么?当然如果你把它放在一个字节缓冲区中,你想要一个指针吗?
-
Ian Collins。
Why? Surely if you are putting it in a byte buffer, you want a pointer?
--
Ian Collins.
On 1 ??30è?,????4ê±12·?, Ian Collins< ian-n ... @ hotmail.comwrote:
On 1??30è?, ????4ê±12·?, Ian Collins <ian-n...@hotmail.comwrote:
Allen写道:
Allen wrote:
我想将地址打包到字节缓冲区。所以我需要将它转换为
整数值。
I want to package an address to byte buffer. So I need to cast it to
integer value.
为什么?当然如果你把它放在字节缓冲区中,你想要一个指针吗?
-
Ian Collins。
Why? Surely if you are putting it in a byte buffer, you want a pointer?
--
Ian Collins.
是。
我将RPC输出参数打包到字节缓冲区。所以我需要记住
输出变量地址。
怎么做?
Yes.
I package RPC output parameter to a byte buffer. So I need to remember
the output variable address.
How to do it?
Allen napsal:
Allen napsal:
我想将地址打包到字节缓冲区。所以我需要将其转换为
整数值。
如何投出它?
const char * ptr = 0x0013e328;
int value =< cast(ptr); //使用reinterpret_cast?
I want to package an address to byte buffer. So I need to cast it to
integer value.
How to cast it?
const char * ptr = 0x0013e328;
int value = <cast(ptr); // use reinterpret_cast?
是的,使用reinterpret_cast。或者你可以使用工会
联盟演员
{
const char * szptr;
const int * iptr;
};
在这两种情况下你都要承担这次转换的责任
(你声称你知道它是如何存储在那里的)。但是对于铸造指针
应该没有问题。
Yes, use reinterpret_cast. Or you can use union
union Cast
{
const char* szptr;
const int* iptr;
};
In both cases are you taking the responsibility for this conversion
(you claim you know how is it stored there). But for casting pointers
there should be no problem.
这篇关于如何将指定的类型指针强制转换为整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!