[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OS/2 Patches (4)

From: Andreas Buening
Subject: Re: OS/2 Patches (4)
Date: Tue, 05 Nov 2002 22:35:14 +0100

Neal H. Walfield wrote:
> > I don't know who maintains the lib subdirectory. However, it's
> > still a bad idea not to initializes global variables.
> Crap.  Learn the difference between the bss and data sections.

Ah, everytime it's a pleasure for me to discuss the different
points of view in an highly intellectual and philosophical
manner as well as to argue about the pro's and con's of
various cultural techniques and and their theoretical and
practical implementations.

If you're offended because I said "I don't know who maintains
the lib subdirectory" and you're the maintainer then I can
tell you I meant "I don't know for sure whether this mailing
list is finally responsible for the lib/* files but I submit
this small patch nevertheless".

And yes, unfortunately, I know that this (to use your words)
crap is Standard C. It's unbelievable, but true.
As well as implicit int declarations. As well as "Different
names with external linkage must differ (other than in case)
within the first six characters". But the fact that this is
a Standard does neither mean that this is "good" nor that
it is reasonable to use this "feature".

Ah, you're asking why I think this is a bad idea? A good
question. These so called "tentative definitions" are a very
funny feature. You can define as many variables of an arbitrary
type with the same name, one in each source file. Cool, isn't
it? This results in a so called "common" variable because
all these variables share the same address. Why is this a
bad programming style? Consider the following example:

char *program_name; /* name of the program */

void set_program_name(char *s)
  program_name = s;

int program_name; /* we have found a program */

int search_prog(char *path)
  /* do something with program_name */

int main(int argc, char *argv[])

  /* found out whether xyz is installed */


This is standard compliant C code. If program_name had an
initializer the linker would print an error message.
And now the big question arises: What will happen now?
"int program_name" and "char *program_name" have the same
size and address. In this case any further read access to
"char *program_name" would most likely result in a
segmentation fault. Nice, isn't it?

If you use common blocks for your own printf-hello-world
programs that's your problem. But using common blocks for
a library is a rather bad programming style. The name
"program_name" is not that an unlikely name that no user
will ever use it for his own programs.

Just my 2 cents.

Please reply any comments directly to me because I haven't
subscribed to any gettext mailing list.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]