infinite loop

B

bob

periodically, my program seems to get stuck in an infinite loop. i
have a lot of loops though, so i don't know which one. any ideas how
to find out? i'm using dev-cpp. i think having the debugger figure it
out might be best but i don't know if it can.
 
G

Gianni Mariani

periodically, my program seems to get stuck in an infinite loop. i
have a lot of loops though, so i don't know which one. any ideas how
to find out? i'm using dev-cpp. i think having the debugger figure it
out might be best but i don't know if it can.

When it gets stuck in an infinite loop, attach to it with the debugger
and see where it is.
 
A

Artemis Fowl

Try this. Print out a unique id of sort for each loop before entering
it. You will know where the code gets stuck. Or you can always use the
debugger to find out. Its got plethora of tricks up its sleeve.
Hope this helped!
-AF
 
T

TIT

(e-mail address removed) sade:
periodically, my program seems to get stuck in an infinite loop. i
have a lot of loops though, so i don't know which one. any ideas how
to find out? i'm using dev-cpp. i think having the debugger figure it
out might be best but i don't know if it can.

Do some debugging by isolating the execution path. The simplest
way is just to do some printing at certain execution waypoints.

Even though you have a lot of loops, with a few printings
you should be able to track down the faulty ones.

Use assert here and there to secure vital data in debug mode.

TIT
 
M

Mike Wahler

periodically, my program seems to get stuck in an infinite loop. i
have a lot of loops though, so i don't know which one.

So check them all.
any ideas how
to find out? i'm using dev-cpp. i think having the debugger figure it
out might be best but i don't know if it can.

It can't but you can, by using it. Use breakpoints.

Another way without using a debugger:

cout << "starting loop 1:\n";
for(/* etc */)
{
}
cout << "finished loop 1:\n";

/* other code */

cout << "starting loop 2:\n";
while(/* etc */)
{
}
cout << "finished loop 2:\n";


/* other code */

/* etc, etc */

-Mike
 
N

Neil Cerutti

Try this. Print out a unique id of sort for each loop before
entering it. You will know where the code gets stuck. Or you
can always use the debugger to find out. Its got plethora of
tricks up its sleeve. Hope this helped!

When doing so, it can help to use std::cerr instead of std::cout,
since I believe std::cerr is unbuffered by default.
 
B

bob

i don't see why there isn't an easy way to just make it print out the
line number it's on when i terminate it.
 
M

mlimber

O

Owen Jacobson

i don't see why there isn't an easy way to just make it print out the
line number it's on when i terminate it.

In the resulting executable program, there may or may not _be_ any line
numbers. The compiler doesn't necessarily translate each line of
source code into a discrete sequence of object code; compiler optimization
will even further modify the resulting program.

Now, yeah, if you built the program with debug information most debuggers
can relate positions in the code to the line of source that caused them,
but that's a compiler- and platform-specific matter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top