printing to screen prior to a segmentation fault

I had this issue, and I'm not sure exactly what's going on.

Here are two lines from my code.

cout<<"grrr";
if(leaf->p->color==1){...blahblahblah...}

I was getting segfaulted at the if statement because p had not been properly assigned. But the cout<< that I had put in as a diagnostic tool was not printing to the screen, which made me think that the error was further up. Finally I used gdb to find the exact location of the error, and saw that it occurred at the if statement. But why wouldn't the cout<< print to the screen if the error happened after the cout<< command?

As it turns out, this updated code does print the text before the segfault.

cout<<"grrr\n\n";
if(leaf->p->color==1){...blahblahblah...}

So adding the newlines allows the text to print out before I get segfaulted out of the program. What's going on? Is this some printscreen buffer flushing issue, or something else?

(Ah Matlab, you have spoiled me rotten.)
printscreen buffer flushing issue


Yes. It's not related to the segFault.
Last edited on
Insert std::endl instead of \n to force a flush after the newline.
Topic archived. No new replies allowed.