Author Topic: Is the result of "printf" and "debug watch" different?  (Read 4378 times)

Offline hnust_zhangyehua

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Is the result of "printf" and "debug watch" different?
« Reply #15 on: July 04, 2016, 12:55:52 pm »
A very important problem that I forget to tell you :'(
This code runs at Visual Stdio is good, in other words, when the code run at the Visual Stdio, its result, on the "printf windows" whether  after execute or in the debugging, is same. Moreover, the result of array C in the  Visual Stdio is same as the other result when the code is debugging in the codeblocks.

Therefore, I can get a conclusion that codeblocks goes wrong :'(

Online BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2434
Re: Is the result of "printf" and "debug watch" different?
« Reply #16 on: July 04, 2016, 03:38:08 pm »
codeblocks per se does not go wrong, because codeblocks is not a compiler and for this it has nothing to do with your code / your compiled program...
I don't think that in so simple code a compiler bug triggers so i think your code is wrong on one point... I made a quick look, but i didn't find anything critical (beside that you are not deleting Q after a new call)... One thing i can think of is, that cin reads some garbage from the input buffer...
you can try cpp check to analyze your code: http://cppcheck.sourceforge.net/

i have to admit, that your code is not easy to read and to understand...
Code: [Select]
void creat(List &T,int e) //build the tree
{
    if(!T)
    {
        LNode *S;
        S=new LNode;
        S->data=e;
        S->lchild=S->rchild=NULL;
        T=S;
    }
    else if(e>T->data)creat(T->rchild,e);
    else if(e<T->data)creat(T->lchild,e);
}
You assign T a new allocated List, but what happens with the old List??? This is for example a memory leak you should avoid. And i think the whole code is full with this... If your code works, it is luck or tolerance of your OS or compiler, but at one point it will blow up... The consequence is (or better can be) that your program works under debug mode but not in release...

sry i can't help more, but this is now out of the scope of this forum, as you don't have a problem with codeblocks, but with the underlying compiler...


« Last Edit: July 04, 2016, 03:40:18 pm by BlueHazzard »

Offline raynebc

  • Almost regular
  • **
  • Posts: 203
Re: Is the result of "printf" and "debug watch" different?
« Reply #17 on: July 04, 2016, 08:50:41 pm »
That linked list logic looks wrong to me.  When you add a link, it correctly sets either the lchild or rchild pointer of the list's current tail, but the other pointer is left at its initialized value of NULL.  Unless you ensure both pointers are correctly adjusted every time you append or prefix a link, it will not correctly function as a doubly linked list.