By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,513 Members | 1,693 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,513 IT Pros & Developers. It's quick & easy.

infinite loop

P: n/a
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.

Oct 28 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
bo*@coolgroups.com wrote:
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.
Oct 28 '05 #2

P: n/a
TIT
bo*@coolgroups.com 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
Oct 28 '05 #3

P: n/a
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

Oct 28 '05 #4

P: n/a
<bo*@coolgroups.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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
Oct 28 '05 #5

P: n/a
On 2005-10-28, Artemis Fowl <ne******@gmail.com> wrote:
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.

--
Neil Cerutti
Oct 28 '05 #6

P: n/a
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.

Neil Cerutti wrote:
On 2005-10-28, Artemis Fowl <ne******@gmail.com> wrote:
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.

--
Neil Cerutti


Oct 28 '05 #7

P: n/a
[Top-posting corrected]

b...@coolgroups.com wrote:
Neil Cerutti wrote:
On 2005-10-28, Artemis Fowl <ne******@gmail.com> wrote:
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.


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.


Don't top-post. See
http://www.parashift.com/c++-faq-lit...t.html#faq-5.4 .

Using the debugger, you can stop the program *anywhere*. That's even
better than printing because the debugger will take you directly to the
line it was executing when you stopped it. Try it out!

Cheers! --M

Oct 28 '05 #8

P: n/a
On Fri, 28 Oct 2005 13:46:02 -0700, bob wrote:
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.
Nov 1 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.