lkml.org 
[lkml]   [2000]   [Nov]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] removal of "static foo = 0"
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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 12:47    [W:0.169 / U:4.276 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site