[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: OS/2 Patches (4)
From: |
Bruno Haible |
Subject: |
Re: OS/2 Patches (4) |
Date: |
Wed, 6 Nov 2002 15:28:02 +0100 (CET) |
Andreas Buening wrote:
> > > it's still a bad idea not to initializes global variables.
> >
> > Crap. Learn the difference between the bss and data sections.
>
> unfortunately, I know that this (to use your words)
> crap is Standard C. It's unbelievable, but true.
Please read the standards before complaining about them. Quoting
ISO/IEC 9899:1999 (a.k.a. ISO C 99) section 6.7.8 paragraph 10:
If an object that has automatic storage duration is not initialized
explicitly, its value is indeterminate. If an object that has static
storage duration is not initialized explicitly, then:
- if it has pointer type, it is initialized to a null pointer;
- if it has arithmetic type, it is initialized to (positive or
unsigned) zero;
- if it is an aggregate, every member is initialized (recursively)
according to these rules;
- if it is a union, the first named member is initialized (recursively)
according to these rules.
and section 6.2.4 paragraph 3:
An object whose identifier is declared with external or internal
linkage, or with the storage-class specifier static has static storage
duration. Its lifetime is the entire execution of the program and its
stored value is initialized only once, prior to program startup.
> As well as "Different
> names with external linkage must differ (other than in case)
> within the first six characters".
This also is an urban legend. In ISO C 99 the first 255 characters
(at least) are significant. And of course 'x' and 'X' are different
names. This is C, not Pascal or Fortran.
> 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? ...
Most people agree that using the "common" variables feature of
Unix linkers is bad, because it's unportable. But this doesn't
make implicitly initialized (= BSS allocated) variables a bad
feature.
Similarly: Division by zero is bad, but that doesn't make the
use of division bad by itself. You just have to be careful when you
use it.
Bruno
Re: OS/2 Patches (4), Bruno Haible, 2002/11/11