The importance of the "all clear" message
Sometimes when you program (ok, ok, when I program at least), you commit one of those stupid errors - that completely sidetracks you. So you use every tool you have at your disposal, include google and gmane, but come up with nothing. This is where best practices may save you.
This weekend, I've been trying to get a network based project started - only to discover that I always got a segmentation fault when trying to open a listening socket on the server.
This was pretty annoying, and I did all the little things I usually do to pinpoint the error fast and easily. I sprinkled little printed statements throughout the code, when that didn't help I copied known good code. When that didn't help, I started googling for this network function, and the word segfault.
As far as I could tell, the only difference between the working and the segfaulting code was context. The working code was compiled as C, and the segfaulting as C++. So I added that to my search. I also ran ldd to see that the bad code linked all the right libs - and it did.
I was going mad.
So I stepped through the code with gdb (a debugger), and realized that the code didn't segfault where I thought it did. I just had not added an "all clear" after the last piece of network code - so I never knew it worked.
Moral of the story? Make damn sure you know where the error is. Add little prints at the most stupid places, step through the most boring details with the debugger, and if google comes up with everything but your exact error - be suspicious.
Happy coding!
- By ibnalhazardous at 04/13/2008 - 19:21
- goofs
- programming
- ibnalhazardous's blog

Post new comment