D
DaveC
I always used to initialise variables at declaration, then a couple of
colleagues started telling me it was bad practice and that the compiler
should be left to spot the use of uninitilised variables and hence
possible bugs.
Your thoughts on the above would be welcome (as an aside), but my main
problem follows.
Now I've recently upgraded to gcc 4, and I find I'm missing the compiler
warnings I used to get on gcc 3 regarding uninitialized vars (the warning
flags -Wall, etc., are still there, I just don't get the warning messages).
Consider the code below. I expected to get a warning about foo being
uninitialized, but I don't. I'm sure there's a simple explanation, but I
can't see it.
int
main(void)
{
int foo;
int i;
i = 0;
while (i) {
if (i == 10) {
foo = 50;
}
if (foo) {
printf("%d\n", foo);
}
++i;
if (i > 20) {
break;
}
}
return 0;
}
colleagues started telling me it was bad practice and that the compiler
should be left to spot the use of uninitilised variables and hence
possible bugs.
Your thoughts on the above would be welcome (as an aside), but my main
problem follows.
Now I've recently upgraded to gcc 4, and I find I'm missing the compiler
warnings I used to get on gcc 3 regarding uninitialized vars (the warning
flags -Wall, etc., are still there, I just don't get the warning messages).
Consider the code below. I expected to get a warning about foo being
uninitialized, but I don't. I'm sure there's a simple explanation, but I
can't see it.
int
main(void)
{
int foo;
int i;
i = 0;
while (i) {
if (i == 10) {
foo = 50;
}
if (foo) {
printf("%d\n", foo);
}
++i;
if (i > 20) {
break;
}
}
return 0;
}