Sign in to follow this  

cout, the root of all evil

This topic is 4837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

After days of thoroughly testing a project I'm ready to compile it in its final incarnation, so I remove all my debugging cout's. Segmentation Fault. Great. I put them back in, and I narrow it down to one cout that when it's there, whatever it prints (I've tried many, example "WHY, GOD, WHY?"), the segmentation fault occurs. I've never encountered this before, so I'm sort of clueless as to what this is a symptom of. Obviously I've messed up my memory somewhere, but why then would the program run fine with this stupid cout in it and not without? Anyone have any tips?

Share this post


Link to post
Share on other sites
Chris-
Yeah, I'm not saying it is, but the fact remains that my program executes flawlessly with the cout that isn't tied to any function (i.e. not getting its intput from any function), but it segfaults without it.

lonesock-
Trying that out now...

Share this post


Link to post
Share on other sites
Heh, I've had similar things occur with printf [in plain jane C, but the same applies...]. Essentially the cout isn't breaking your code, it's causing whatever buffer overflow you're causing [edit: in some probably wholy unrelated area] to overwrite something innocent [like the cout string] rather than something vital. The program will happily print garbage if the cout debugging message gets overwritten. Overwrite a pointer's value or something though, and things go downhill quickly.

[edit: the only real way to find the damn problem is generally to narrow it down to a cout that your program won't run without, then step through the code evaluating the cout. Once the output changes, that's where the bug is.

Needless to say, it's a pita.]

Share this post


Link to post
Share on other sites
I suppose the obvious candidates are:

- Race condition - cout is slowing down your program sufficiently to avoid a race condition that otherwise crashes it
- Uninitialised variables - use of cout is causing variables that are uninitialised to contain different values, which happen to not crash.

Mark

Share this post


Link to post
Share on other sites

This topic is 4837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this