infinite loop stops cout (maybe)

I think this program is stuck in an infinite loop however i can't find where because when i try putting cout in various places as markers it isn't printing anything. Here is int main. I'll post the rest of the code later if needed.

1
2
3
4
5
6
7
8
9
10
11
  int main()
{
    cout << "1 "; //marker
    InitWheel(); //initialize "wheel"
    cout << "2 "; //marker
    InitRobots(); //initialize "robots"
    cout << "3 "; //marker
    TestRecord(); //next level debugging stuff that I'm trying to get to work
    cout << sD; //output
    return 0;
}


When the code is run the console window opens as it should but then nothing else happens. My processor fan immediately starts spinning so i assume it's stuck doing something but it's not printing anything. It does print the markers if the loop is avoided though. In case it is relevant, I'm running this program in code blocks on ubuntu.

So i suppose what I'd like to know is why it's doing this and if possible how to get it to stop doing this and/or how to debug the program anyways.

Update:
i fixed a bug that would have caused an infinite loop and running the code gave me the error message "Segmentation fault (core dumped)" after 148 seconds. Which apparently means that it tried to access memory that it doesn't have access to (I have no pointers but I do have an array so i guess it's that). Regardless I still wish to know why cout doesn't work in this case.
Last edited on
I'll post the rest of the code later if needed

In this case it might be but if the code is too large you may wish to post it online somewhere first and send the links through
Yes please share more of your code. You did #include <iostream> correct?
In this case it might be but if the code is too large you may wish to post it online somewhere first and send the links through

You can use this link to paste your code for your convenience if that is the case.
http://rextester.com/l/cpp_online_compiler_visual
Regardless I still wish to know why cout doesn't work in this case.
cout has an associated buffer where it stores pending output until it is explicitly flushed or it fills up.

When using poor-man's debugging (print statements) try printing to standard error -- using std::cerr. std::cerr specifically flushes its' buffer after every write. Alternatively, flush std::cout (or whatever stream) explicitly by inserting std::flush or std::endl.

Another thing that could be happening is that program flow is not reaching any or some of the calls. There's no way to tell without context.
Last edited on
here's the whole code in it's current form
http://rextester.com/FYQBW95904

it would seem that it wasn't printing due to the buffer mbozzi mentioned

currently I'm still getting the segmentation fault error after about 230 seconds. I've just found that this is caused by WheelColorIncriment being called a third time then letting the TestRecord function progress. The error does not occur if WheelColorIncriment is called 4 times (until its called more in the main loop) so I have no idea what's happening
Last edited on
I found the segmentation fault was caused by the incrementing functions counting one too many times and then passing that to an array someplace else. I have fixed the error and now the code works fine (also due to the highly exponential nature of the math this code does it now runs 100 times faster).
Topic archived. No new replies allowed.