bug-gnu-utils
[Top][All Lists]
Advanced

[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: Thu, 07 Nov 2002 01:03:13 +0100

Bruno Haible wrote:
> 
> 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:

[it has a well defined initial value]


> > 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.

Unfortunately, I'm not familiar with the latest C99. For that legend
I referred to http://www-ccs.ucsd.edu/c/declare.html#Linkage
which claims to rely on ISO/IEC 9899:1990.


> > 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.

This I don't understand. If the initial value of that variable
is indeterminate why should anybody use this feature?
Is it just because it saves 4 bytes of data size? To my knowledge
even the identifier "program_name" requires 13 bytes storage in
a shared library for resolving names. You can most likely save
much more memory by using -Os -s and aligning data to a 1 byte
boundary.

And if there are (non Unix) linkers that can't handle this correctly
why should any GNU program use it? I remember GNU is Not Unix.
This is no provocation. I'd just like to know why. I'd never
use common variables if there is any other way.


> 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.

This normally raises a SIGFPE so that it's clear what's wrong.


Bye,
Andreas




reply via email to

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