指针在函数调用后更改其地址
pointer is changing its address after a function call
我对这部分代码有一个问题:
const float *dest = (float*)varPtr1.memoryPointer;
float temp;
ReadFromMemory(temp);
.
.
continue the rest of treatment with 'dest' and 'temp'
一切正常,当到达第二行时,"dest"具有正确的值,但是,在调用函数ReadFromMemory((后,"dest"指针将其地址更改为 0x100000000,当然它的值变得错误(指向另一个地址(。
所以我的问题是,为什么"dest"在调用func后会改变其目标,尽管它已经超出了这个范围。
注意:温度是正确的
template<typename T>
void myClass:: ReadFromMemory(T &var, int var_pos)
{
if(cons64requested)
{
cons64requested = false;
}
else
{
if(var_pos==2)
{
const4NextInstruction = snd_param;
}
else
{
const4NextInstruction = fst_param;
}
}
memcpy(&var,&const4NextInstruction,0x8);
}
这个问题的解决方案是不传递 temp 作为引用,而是传递它的指针。 因此,函数声明如下所示:
void myClass:: ReadFromMemory(T *var, int var_pos)
相关文章:
- 函数调用中参数的顺序重要吗
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 变量没有改变?通过向量的函数调用
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- 我知道函数调用中存在歧义.有没有办法调用foo()函数
- 模板函数调用
- 获取从C++中同一类中的构造函数调用的方法返回的值
- 析构函数调用
- 成员函数调用和C++对象模型
- 使用共享指针的函数调用,其对象应为 const
- C++:编译时检查匹配的函数调用对?
- 函数调用C++中的参数太少
- 来自 DLL 的函数调用 [表观调用的括号前面的表达式必须具有(指向-)函数类型]
- 指针在函数调用后更改其地址
- 地址处的 C++ 值与函数调用后的预期值不同
- 获取函数调用方的地址?
- 可以valgrind报告丢失块的内存地址(用于调试递归函数调用)
- 用于后续函数调用的相同内存地址
- c++ 函数调用的参数推送顺序不反映堆栈中参数的地址