possible to have some C variables uninitiialized?

Ian Lance Taylor ian@zembu.com
Sat Apr 1 00:00:00 GMT 2000


   From: Paul Andrews <paul.andrews@smartmove.co.nz>
   Date: Wed, 19 Jan 2000 15:15:58 +1300

   Does anyone know why the section attribute only works on initialised
   variables? The manual says it's because of the way the linker works but the
   explanation is a bit lost on me...

gcc normally declares uninitialized variables as common variables.
This means that you can do
    int i;
in one file and
    int i = 4;
in another file, and have i in the first file refer to the same
variable as i in the second file.  This is a common Unix extension to
the ISO C standard.

A common symbol can not be in a section.  If it were, it would be a
defined symbol, not a common symbol.

Even when gcc does not use common symbols, as with the -fno-common
option, it still puts uninitialized variables in the BSS section.
This means that the variables do not take up any space in the
executable, which means that the executable is smaller and loads
faster.  Space for these variables is automatically allocated by the
loader.  Again, a variable can not be both in the BSS section and in
some section which you name.

gcc could certainly support the section attribute on an uninitialized
variable by simply treating the variable as having been implicitly
initialized to 0.  So far the gcc maintainers have chosen to treat the
section attribute as not modifying the usual treatment of
uninitialized variables.

Ian

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com



More information about the crossgcc mailing list