infinite loop

Discussion in 'C++' started by bob@coolgroups.com, Oct 28, 2005.

  1. Guest

    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, 2005
    #1
    1. Advertising

  2. 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.
     
    Gianni Mariani, Oct 28, 2005
    #2
    1. Advertising

  3. Artemis Fowl Guest

    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
     
    Artemis Fowl, Oct 28, 2005
    #3
  4. TIT Guest

    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
     
    TIT, Oct 28, 2005
    #4
  5. Mike Wahler Guest

    <> wrote in message
    news:...
    > 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
     
    Mike Wahler, Oct 28, 2005
    #5
  6. Neil Cerutti Guest

    On 2005-10-28, Artemis Fowl <> 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
     
    Neil Cerutti, Oct 28, 2005
    #6
  7. Guest

    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 <> 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, 2005
    #7
  8. mlimber Guest

    [Top-posting corrected]

    wrote:
    > Neil Cerutti wrote:
    > > On 2005-10-28, Artemis Fowl <> 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-lite/how-to-post.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
     
    mlimber, Oct 28, 2005
    #8
  9. 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.
     
    Owen Jacobson, Nov 1, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vedran Vukotic

    infinite loop unexpectly dies

    Vedran Vukotic, Mar 2, 2006, in forum: Perl
    Replies:
    0
    Views:
    4,492
    Vedran Vukotic
    Mar 2, 2006
  2. Alexander Bosch

    Infinite loop when using Server.Transfer

    Alexander Bosch, Oct 28, 2004, in forum: ASP .Net
    Replies:
    11
    Views:
    914
    Steven Cheng[MSFT]
    Nov 10, 2004
  3. Alexander Bosch

    Infinite loop when using Server.Transfer

    Alexander Bosch, Oct 31, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    561
    Steven Cheng[MSFT]
    Nov 1, 2004
  4. Replies:
    5
    Views:
    625
    benben
    Jan 31, 2006
  5. Isaac Won
    Replies:
    9
    Views:
    447
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page