When 0 == 1
My secret project is progressing amazingly well. While I look for a paying job, I've resurrected something that has fascinated me for nearly 20 years, and I'm dusting off my rusty 'C' skills to implement the time-critical elements of the system. I spent the weekend perfecting one of the modules. It works, all the time, no errors. Which is why it's disconcerting to see the final message: "Completed task with 1 errors."
Since I wrote the entire program, I went to the source code to see how this last message is generated. For the 'C' freaks among you, here's the reader's digest version of the code:
int i, ret_code;
ret_code = 0;
for (i=0; i<10; i++) ret_code += function_call(i);
printf("Completed task with %d errors", ret_code);
Seems simple enough. When I saw the error, I went to "function_call", and had it print out the value of it's internal return code before ending. It ALWAYS printed 0. So, now I need to decide - is there an insidious bug in my program waiting to bite my ass when I get too complacent, or is there a bug in the compiler that is conspiring to drive me insane.
My money is on option 2.
No comments:
Post a Comment