Re: [PATCH] removal of "static foo = 0"

Andries Brouwer
2000-11-25T23:16:57Z

On Sun, Nov 26, 2000 at 09:11:18AM +1100, Herbert Xu wrote:

> No information is lost.

Do I explain things so badly? Let me try again.
The difference between

static int a;

and

static int a = 0;

is the " = 0". The compiler may well generate the same code,
but I am not talking about the compiler. I am talking about
the programmer. This " = 0" means (to me, the programmer)
that the correctness of my program depends on this initialization.
Its absense means (to me) that it does not matter what initial
value the variable has.

This is a useful distinction. It means that if the program

static int a;

int main() {
/* do something */
}

is used as part of a larger program, I can just rename main
and get

static int a;

int do_something() {
...
}

But if the program

static int a = 0;

int main() {
/* do something */
}

is used as part of a larger program, it has to become

static int a;

int do_something() {
a = 0;
...
}

You see that I, in my own code, follow a certain convention
where presence or absence of assignments means something
about the code. If now you change "static int a = 0;"
into "static int a;" and justify that by saying that it
generates the same code, then I am unhappy, because now
if I turn main() into do_something() I either get a buggy
program, or otherwise I have to read the source of main()
again to see which variables need initialisation.

In a program source there is information for the compiler
and information for the future me. Removing the " = 0"
is like removing comments. For the compiler the information
remains the same. For the programmer something is lost.

Andries