....
Initialising variables to a safe or default value is mainly a feel-good
thing.
Depends. For me, seeing it in existing code is a warning sign, and I tend to
remove the initialization -- after analysing the code.
....
If your code is correct, then dummy initialisations rarely have a
useful effect. If your code is wrong, then the default values, (often
zero), are as likely to lead to wrong results than an arbitrary value.
Yes, in cases where there is no /useful/ default.
I treat the two forms as a kind of documentation. In my head,
it works like this:
void f(void) {
int i = 0;
...
}
- this value is actually used in the code below, or,
- the code was too complex to analyze for the writer; he wasn't sure
all code paths change the value of i before using the value,
/and/ 0 is a harmless default (maybe it flags an error later on)
void f(void) {
int i;
...
}
- there was no reasonable way to rework this so that i could be initiated
with a meaningful value at its definition, and,
- the writer is confident that all code paths initialize i before using it.
/Jorgen