just another brick in the -Wall
Posted: Sat Jun 21, 2003 4:03 pm
it's been a looong debugging session ... i had enfringed #1 commandment of the C programmer (thou shalt not follow thee NULL pointer) and it need *much* time to discover it.
btw, i've tried something new: the -Wall (enable all warnings) flag of GCC -- so far, i was believing that i needn't warnings, because warnings were boring and didn't give any valuable information.
Hah! how f00lish was i ...
GCC pointed out dozen of uninitialized variables, tons of function that actually returned unpredictable value (often used as a true boolean) and a few "wrong parameters" due to the use of undeclared functions ...
So much horrors .. i even wonder how my code have worked for so long ...
Be wise, guyz. Put your code in the -Wall brick by brick, and do not wait until nothing works to try that marvelous option ...
Then study your C language book until you understand exactly what the compiler is complaining about and only then fix stuff.
a small example is
construct i had in a lot of place ... i thought it was foolish to add a pair of parentheses and have
just to make the compiler pleased ... until i found a line of code i had written myself a few monthes ago and couldn't remember whether it should be "x=y" or "x==y" ... Fortunately the complete operation wasn't too complex so with the comments i had already written, i could figure in this very case, "x=y" was correct, but pretty weird ... but it took me about half an hour to find out !
now that it's written (( x=y )) i hope it will be easier to get convinced that it's an affectation plus a "non-null" test rather than a comparison.
Hope my experience will help you ...
btw, i've tried something new: the -Wall (enable all warnings) flag of GCC -- so far, i was believing that i needn't warnings, because warnings were boring and didn't give any valuable information.
Hah! how f00lish was i ...
GCC pointed out dozen of uninitialized variables, tons of function that actually returned unpredictable value (often used as a true boolean) and a few "wrong parameters" due to the use of undeclared functions ...
So much horrors .. i even wonder how my code have worked for so long ...
Be wise, guyz. Put your code in the -Wall brick by brick, and do not wait until nothing works to try that marvelous option ...
Then study your C language book until you understand exactly what the compiler is complaining about and only then fix stuff.
a small example is
Code: Select all
if (var=constructor()) { ... } else fail("cannot construct object");
Code: Select all
if (( var=constructor() )) { ... }
now that it's written (( x=y )) i hope it will be easier to get convinced that it's an affectation plus a "non-null" test rather than a comparison.
Hope my experience will help you ...