Originally Posted by
rstanley
Typo, obviously! "Good" not "god"! ;^)
Although, some programmers do think C is a religion! ;^)
Side note: the two words actually come from the same root. To be a "good man" for example used to mean a "godly man". Of course the meanings have obviously diverged quite a bit over the millennia. (As in, "He was a good thief"!)
Back to the topic, I almost always initialize variables (global or otherwise) regardless. For me it is simply a matter of style, really, even though the standard does basically guarantee that globals will zero-initialized. That said, there are some instances where I do indeed omit the initialization:
Code:
int ch;
for (;;) {
ch = getchar();
if(ch == EOF)
break;
// do something with 'ch'
}
I think the fact the declaration is "within view" of where it is being used is why I don't have any issues with that. As long as it is obvious that the variable in question is "decidedly uninitialized", why not?