DEV Community

Discussion on: What's the hardest problem you've had to debug recently, and what did you learn from it?

Collapse
 
davidhaile profile image
David Haile

Background: I've been a C programmer since almost the year it was invented. That matters because of the problem that I found today. You'll see it immediately.

int startPosition = 0;

for (int startPosition = 0; startPosition<max; startPosition++) {
// Search for something in a buffer. Break when found.
if (buffer[startPosition] == SEARCHED_VALUE) {
break;
}
}

buffer[startPosition] should contain the value that I was looking for. It took me several hours to figure out why startPosition was always 0!

Part of the problem was the difficult debug environment that involved downloading code to an engine computer and running the diesel engine.