fj1*_*23x 2 c++ memory-address
double address = 3068770752;
std::string hello = (char *)address;
Run Code Online (Sandbox Code Playgroud)
错误:从'double'类型无效转换为'char*'类型
所以,如果我使用类型long或int,这是有效的,但是对于double类型,这是行不通的.我怎样才能做到这一点?
谢谢!
编辑:我正在用C++编写PHP扩展,这是自定义函数"get_memory_data(双地址)"的"内容",在您使用的php中:
<?php
$a = "hello";
$b = get_memaddress($a); //0x123456
$c = hextodec($b); //3068770752
$d = get_memdata($c); //hello
Run Code Online (Sandbox Code Playgroud)
首先将其转换为整数:
char * p = reinterpret_cast<char *>(static_cast<uintptr_t>(address));
std::string i_cause_undefined_behaviour(p);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
595 次 |
| 最近记录: |