C programming sucks

I really love all the cryptic errors you can run into in this fantastic language.

void replayAllPastEvents(DumbThing *dumbThing){
     // read events from disk, bla bla bla
     apply(dumbthing, event); // <- explosion in this call
     // ...

The code did compile but crashed due to a segmentation fault in the apply function.
Can you spot the error?

It is a minor typo on the apply line. Even when I have removed all the code above that line it is still quite hard to detect.

But why on earth did not the compiler throw an error on this?

It turned out that I had a function called dumbthing defined elsewhere and for some reason, the c-compiler forgot to warn me about this type error here since it was to busy warning about an implicit function declaration instead. It was not until I got tired of debugging this issue and went on to fixing that warning that the real reason behind the crash was revealed.

(And yes I know, fault was all mine in the end, but still, feels lot better blaming somebody else…)

No comments yet.

Leave a Reply