unpredictable behaviour

Mar 8, 2008 at 12:47pm
Dear All,

I use g++ to compile my code.

I have a complex function that uses a linked list store data elements. During the run it constantly adds and removes elements from it.

However, recently when I run the code, it seemed to be behave very unpredictably. It is suppose to traverse through the list (using a loop) and add new elements to the list when required. However, it was not doing it in the order i had expected it to do.

Accidentally i found that when i added the statement "cout << endl;" to specific areas of my code it seems to work fine. This seems odd as non of the variables are changed in the code. I am baffled by it and would like to know if anyone has ever come across such a problem.

I know i have explained my problem very vaguely. but what i want to know is how could it be possible for a code to work differently if you add a simple print out statement. Do the pointers get corrupted? Could it be a bug in g++?

thanks,
anand
Topic archived. No new replies allowed.