Noah Roberts wrote:
aa*********@gmail.com wrote: Hi,
I have written a program (my first big program in c++). When I run the
program it gives segmentation fault but when i use a printf statement
to debug the program, it runs normally. I am very confused that what
may be the reason?
Of course I dont want to use printf because it is in loop and prints so
many things which I don't want.
http://en.wikipedia.org/wiki/Heisenbug#Heisenbugs
Thanks everybody for the reply.
After using a debugger it showed me some memory leaks but I am
unable to understand this one. Debugger message is
==11474== Use of uninitialised value of size 8
==11474== at 0x804F03B: FindTree(AnswerPoint, AvlNode*)
(avltree.cc:65)
==11474== by 0x8049BED: main (prog2.cc:652)
And the part of avltree.cc looks like
================================================== =====
Position_tree
FindTree( AnswerPoint X, AvlTree T )
{
if( T == NULL )
{
return NULL;
}
if( X.distance < T->Element.distance ) // ==>debugger is
talking about this line
return FindTree( X, T->Left );
if( X.distance > T->Element.distance )
return FindTree( X, T->Right );
if(X.distance==T->Element.distance)
{
if(X.pid==T->Element.pid)
return T;
else
{
if(X.pid>T->Element.pid)
return FindTree(X,T->Right);
else
return FindTree(X,T->Left);
}
}
return T;
}
================================================
The line about which debugger is talking is shown in the above code.
But I have made it pretty sure that in prog.cc at line 652 , the
distance value is not unitialized.
Do you get some idea of where the error may be?
Can I use some if statement to check if the value is unitialized or
not?
e.g; can i say
if(X.distance==NULL)
printf("No value in
X.distance");
X.distance is a double value.
Thanks again for your help.
Regards,
Aamir