Again a small C++ debugging report

Posted on:July 02 2010

I love C++, after all, it's still the most powerful high level language out there. There is nearly nothing you can't do with it. But sometimes, it totally annoys me. Like this problem which hits me about 4 or 5 times a year:

Yesterday, I had a bug in my program where I couldn't figure out why it was happening. It was reproducible, but made no sense. The debugger showed the program did the right thing but the output wasn't correct. So I debugged the program for about 30 minutes, until I gave up.

Then, I cleaned the built object files and rebuilt the whole project from scratch. TADA. Bug disappeared. *grml*
I know, this happens from time to time. The built executable gets corrupted somehow and a rebuild helps. But this time I swear: I'll remember: If it makes no sense, rebuild FIRST! :)


I know that kind of problem, and was (in my case) able to track it down to be a combination of changed struct/class sizes and lack of proper build dependencies -> part of the code were built with the "old" assumptions about an object's size/structure, parts were rebuilt with the "new" assumptions, which led to crashes and/or other weird behaviour when "old" and "new" code interacted.
2010-07-02 14:55:00

Yup; I've noticed this immensely when developing iPhone apps - if you're PC is fast enough and the project is small enough it helps to just always clean before a build or make sure to clean out the build directory every hour or so :-D.

2010-07-02 15:29:00

Isn't this more of a compiler problem than a C++ problem?
2010-07-02 15:50:00

I can only say "amen"! ^^
2010-07-02 16:10:00

Been bitten by that more than once in console development.
If any part of the build dependencies is not checked 100% correctly, you'll most probably violate the ODR (one-definition-rule), eventually resulting in a crash.
2010-07-02 16:58:00

Never experienced that. Sounds like a compiler bug...
2010-07-02 18:51:00

Qt SDK aways give me this problem.
2010-07-02 21:09:00

Speaking of difficult bugs...

When I was porting Emacs to the iPhone, I kept getting random segfualts everywhere. Once I cleaned up the build enough to get debugging symbols (the final emacs binary is a memory dump of a semi-compiled version, ugghh), I found out the segfaults were all caused by system calls. ~4 hours later, I find out my system headers were subtly wrong, so these syscalls kept overwriting memory that wasn't allocated.

2010-07-02 23:57:00

my gold rule with vs and xcode : clean, always! :D and i have a doubt, another clean may help
2010-07-03 00:52:00

Here at work I clean everything every morning and rebuild, but at home I only do that when some strange error occurs.

One the other hand: the most annoying bug in the last year was switching my Stunt Marble Racers project from 2 player splitscreen to up to 4 player network: I forgot to resize an array. No crash, it just overwrote some other data leading to strange behaviour. Took me quite some time to figure that out.
2010-07-05 07:31:00

@garixi: Amen
2010-07-05 08:53:00

Add comment:

Posted by:

Enter the missing letter in: "Interna?ional"




Possible Codes

Feature Code
Link [url] [/url]
Bold [b]bold text[/b]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]