为什么这会给使用未初始化的大小为8的值 [英] Why would this give a Use of uninitialised value of size 8
问题描述
在我的代码中,我有一个类名为 membrane
的函数名为 exciteMod()
code> decisions()和一个名为 delta_U
的变量。 exciteMod()
的第一行是 this-> delta_U = 0
。在 decisions()
我有一个指数 -delta_U
( exp(-this-> ; delta_U)
)。这会导致错误使用大小为8的未初始化值。可能导致这种情况的原因是什么?我没有关于在valgrind中生成的 delta_U
的任何错误。
In my code I have a class named membrane
with a function named exciteMod()
, a function named decide()
and a variable named delta_U
. The first line of exciteMod()
is this->delta_U = 0
. In decide()
I have an exponent of -delta_U
(exp(-this->delta_U)
). which cause an error Use of uninitialised value of size 8. What might cause this? I don't have any error about delta_U
which is generated in valgrind.
strong>
下面是代码的相关段:
Here are the relevant segment of the code:
void membrane::exciteMod(){
this->delta_U = 0;
/* Do some stuff which does not directly affect this->delta_U*/
std::tr1::shared_ptr<bead> bit = this->beads.begin();
while (bit != this->nead.end()){
std::tr1::shared_ptr<bead> b = *bit++;
//calculate the doubles U and nextU on b, nothing here gives a warning in valgrind, anyhow U and nextU on b are always defined
this->delta_U += (b->nextU - b->U);
}
decide();
}
void membrane::decide(){
double r = P.r.ran3() // the random function from numerical recepies
double f = - this->delta_U;
if (r > exp(f)){ //this gives the warning even though delta_U is valid
/*stuff*/
}
}
这是警告:
== 467 ==大小为8的未初始化值的使用
== 467 ==在0x300B00D75D:__ieee754_exp(在/lib64/libm-2.5.so中)
== 467 == by 0x300B022FA3:exp(in /lib64/libm-2.5.so)
== 467 == by 0x40BB9A:membrane :: decide()(membrane.cpp:813)
== 467 == by 0x40EBB1:membrane :: exciteMod()(membrane.cpp:639)
== 467 == by 0x413994:membrane :: MCstep(int)(membrane.cpp: 486)
== 467 == by 0x402767:main(main.cpp:14)
==467== Use of uninitialised value of size 8
==467== at 0x300B00D75D: __ieee754_exp (in /lib64/libm-2.5.so)
==467== by 0x300B022FA3: exp (in /lib64/libm-2.5.so)
==467== by 0x40BB9A: membrane::decide() (membrane.cpp:813)
==467== by 0x40EBB1: membrane::exciteMod() (membrane.cpp:639)
==467== by 0x413994: membrane::MCstep(int) (membrane.cpp:486)
==467== by 0x402767: main (main.cpp:14)
Edit:
我应该提到我调用 decision()
的唯一地方在 exciteMod()
。
推荐答案
未初始化值的最可能原因是, code> b_> nextU 或 b-> U
code>本身未初始化。也就是:
The most likely cause of uninitialized value is that at least one of b->nextU
or b->U
that you are adding to delta_U
is itself uninitialized. That is:
foo = 0;
foo += some_uninitialized_value;
if (foo) // Valgrind warns here
你希望Valgrind在foo变为未初始化。
You would like Valgrind to report when foo becomes uninitialized. Unfortunately, doing so produces too many "false positive" warnings to be practical.
您可以插入到 VALGRIND_CHECK_MEM_IS_DEFINED $ c>的循环调用中$ c>(请参阅 Valgrind用户手册),Valgrind将发出确切的信号
delta_U
变为未定义的时刻。
You can insert into your loop calls to VALGRIND_CHECK_MEM_IS_DEFINED
(see Valgrind user manual), and Valgrind will signal the exact moment when delta_U
becomes undefined.
这篇关于为什么这会给使用未初始化的大小为8的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!