Debugging in Dev-C++

Hi,
I have problem with debugging my program in C++. I used to use rand() to generate pseudo-random numbers. The program didn't behave the same way when run "normally" and when run in debug mode. I thought the problem may be int the rand() function, so I made my own:

int a=100, b=200;
int MyRandom()
{return (((a--)*(b++))%RAND_MAX);}

Not only the program still don't run the same in debug and normal mode, but now it soon crasch because of "acces violation".
Why the program does other things when run in debugger? (It should be "anthill" simulation and the "ants" do other things in the debugger.) Is it possible that I somehow acces by a pointer to wrong part of memory and it affects another part in debugger and in normal run?
Why MyRandom() causes the program to crash very early while I didn't notice any crash while using rand (), even after many hours of the program running?
When I use the "step into" option of debugger and run it step by step it seems that the acces violation happens in a class contructor in a part where I don't do anything that may cause acces violation I believe. But the debugger in C++ is strange.
So I have no idea, what the acces violation may cause, why MyRandom() is different than rand() and why the progam in debugger does something else than normal run.
Undefined behavior can do a lot of things. Especially invalid memory writes can overwrite structures used by other parts of the program. Even a small change in the code can cause an invalid memory access that previously more or less reliably trashed non-important data to overwrite "important" data.

Anyway, you should post the part of the code where the segmentation fault happens and the call stack.
You can use the debugger to check the values of various variables to get an idea of what is wrong.
Last, use Code::Blocks - Dev-C++ is outdated and is no longer being developed.
Topic archived. No new replies allowed.