以下是我在 Valgrind 上运行代码时收到的消息
1) 未初始化的值是由堆栈分配创建的 ==16808== 在 0x400EC1: init() (Hite.cpp:90)
2) 大小为 8 的无效读取
xmin=0.000000, xmax=1.000000, dx=0.010000, dt=0.000208, c=3.000000
==2763== Conditional jump or move depends on uninitialised value(s)
==2763== at 0x3E5420E836: __ieee754_exp (in /lib64/libm-2.12.so)
==2763== by 0x3E54224A81: exp (in /lib64/libm-2.12.so)
==2763== by 0x400F88: init() (Hite.cpp:96)
==2763== by 0x4010C8: main (Hite.cpp:114)
==2763== Uninitialised value was created by a stack allocation
==2763== at 0x400EC1: init() (Hite.cpp:90)
==2763==
==2763== Use of uninitialised value of size 8
==2763== at 0x3E5420E8EC: __ieee754_exp (in /lib64/libm-2.12.so)
==2763== by 0x3E54224A81: exp (in /lib64/libm-2.12.so)
==2763== by 0x400F88: init() (Hite.cpp:96)
==2763== by 0x4010C8: main (Hite.cpp:114)
==2763== Uninitialised value was created by a stack allocation
==2763== at 0x400EC1: init() (Hite.cpp:90)
我们如何克服出现的这些错误
90 void init() {
91 double xmin=0;
92 double xavg = 0.5*(xmin+xmax);
int main(int argc,char **argv) {
112 printf("xmin=%f, xmax=%f, dx=%f, dt=%f, c=%f\n",
113 xmin=0,xmax=0,dx=0,dt=0,c=0);
114 init()
;