infinite loop

This is a discussion on infinite loop within the C++ Programming forums, part of the General Programming Boards category; my friend is running an infinite loop just displaying a message and beeping on a new line and hes been ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    255

    infinite loop

    my friend is running an infinite loop just displaying a message and beeping on a new line and hes been doing it for an hour. hes running windows XP Pro with 512 RAM

    if memory serves correctly this should crash you computer. at least it did on older windows. so is there a reason his computer hasnt crashed yet? yea and hes new with C++ and he wrote this so im sure its bad and sucky. and its been running the whole time cause the beeps keep going off.

    so why isnt his computer crashed yet?
    hooch

  2. #2
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    The reason its repeating the message infinite times is because an incorrect datatype was entered into cin. For example he is suppose to enter an int value, but instead enters the character 'v', cin fails and flips out. That doesn't mean the programmers bad or whatever, it could happen to you, and probably has.

    I use the following code to check for cin fails:

    Code:
    //after calling cin, call InputCheck();
    
    inline void ClearStream (std::istream& in)
    {
      in.clear ();
      in.ignore (std::numeric_limits <std::streamsize>::max (), '\n');
    }
    
    inline bool InputCheck ()
    {
      if (std::cin.fail()) {
        std::cerr << "Error: invalid input entry\n";
        ClearStream (std::cin);
      } else {
        return 1;
      }
    
      return 0;
    }
    Anyway, his computers probably not crashing because the console is limited to how much text it can display (as you would see if you tried scrolling up, its limited to like 2 pages length). If its only displaying say 1000 words, thats still only like.. 20000 bytes or something, 20-70kb approx. max for the text. Couldnt be more than 1mb. You could check by hitting ctrl+alt+del and seeing how much ram its using, probably around 1500 kb is my guess. Thats not very much, considering World of Warcraft runs up to 600 mb.
    Last edited by Dae; 09-22-2005 at 11:26 PM.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    so what newer versions of windows have a text limit to prevent crashing? cause it defently crashed on windows 98 since i always made infinite loops on accident lol
    hooch

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    140
    I wouldn't think an infinite loop that just prints a message to the console should ever crash windows. (even windows 98).

    More likely the infinite loops you wrote that did cause a crash, were using resources (allocating memory) ,you vioalted an array boundary, or something similar.
    Last edited by spydoor; 09-23-2005 at 09:05 AM.

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Code:
    for(;;){}
    Execute this script on your computer, then watch it die/crash.
    (You might notice that it maxs the CPU out.)

  6. #6
    Registered User Vamslay1415's Avatar
    Join Date
    Sep 2005
    Posts
    4

    Infinite Loop

    Quote Originally Posted by Cool-August
    Code:
    for(;;){}
    Execute this script on your computer, then watch it die/crash.
    (You might notice that it maxs the CPU out.)
    I'm Ssjnameks friend i tried that code and it did not successfully crash my computer. Thanks Though

  7. #7
    ~Team work is the best!~ wakish's Avatar
    Join Date
    Sep 2005
    Posts
    85
    hey common an infinite loop dn't crash a system!

  8. #8
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Quote Originally Posted by Vamslay1415
    I'm Ssjnameks friend i tried that code and it did not successfully crash my computer. Thanks Though
    Is there a reason you WANT to crash your or anybody else's computers?
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  9. #9
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    nah i just remeber i had done it before with some kind of infinite loop and well curiousity kills cats you know lol
    hooch

  10. #10
    Registered User Vamslay1415's Avatar
    Join Date
    Sep 2005
    Posts
    4
    Quote Originally Posted by jmd15
    Is there a reason you WANT to crash your or anybody else's computers?
    I have no real reason for wanting to crash my computer other then i would like to know how and to have bragging rights that I have done it. Although I don't know anyone who will care that I crashed my computer on purpose by my self.

  11. #11
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Use this then, Windows boy:

    Code:
    #include <stdlib.h>
    
    void main(){ //void? Oh no he didn't.
        system("shutdown -f");
    }   //I'm not returning any value. Does that upset you?
    There. "Crashed."

  12. #12
    Set Apart -- jrahhali's Avatar
    Join Date
    Nov 2002
    Posts
    256
    bravo Krak for posting that snippet.
    I wouldn't be surprised if some members just stopped posting all of a sudden.
    Clear the mines from our Shazbot!
    Get the enemy Shazbot!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2009, 11:24 PM
  2. Cosine fucntion and infinite loop.
    By youareafever in forum C Programming
    Replies: 2
    Last Post: 11-07-2008, 03:45 AM
  3. Infinite Loop with GetAsyncKeyState
    By guitarist809 in forum Windows Programming
    Replies: 1
    Last Post: 04-18-2008, 12:09 PM
  4. Switch statement = infinite loop
    By Lucid003 in forum C++ Programming
    Replies: 10
    Last Post: 10-10-2005, 12:46 AM
  5. stays in loop, but it's not an infinite loop (C++)
    By Berticus in forum C++ Programming
    Replies: 8
    Last Post: 07-19-2005, 11:17 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21