Uninitialized global data (was Re: Global variables)

der Mouse mouse at mcgill-vision.UUCP
Tue Mar 8 15:06:30 AEST 1988


In article <1744 at phoenix.Princeton.EDU>, rjchen at phoenix.Princeton.EDU (Raymond Juimong Chen) writes:
> From someone whose attribution has since vanished:
>> The manual seems to indicate that only initialized global data will
>> go here, but isn't all global data implicitly initialized to zero if
>> not otherwise specified?

All statically-allocated data are initialized to zero unless they are
explicitly initialized to something else.  This includes both things
declared static and normal global data.

> I believe that global data initialized to zero go into a special
> segment called "bss".  What it means is (I think) that when the
> program is loaded, the loader allocates the requisite amount of space
> and initializes it to zero at runtime.

This is a UNIXism; not all systems have anything like UNIX's bss
segment, and even fewer of them actually call it bss.  As to what it
means, you are perfectly correct.  It's sort of a trivial form of data
compression: it's something like run-length compression for zero data
only.

On the other hand, this has its ambiguities.  Imagine a machine on
which integer zero, floating zero, and null pointer have three
different bit patterns.  Now, what is the following datum on program
startup?  Presumably it's one of the three, or possibly all-bits-zero
regardless of whether this matches any of the above three....  Could
someone with access to the draft clear this up?

union { int i; float f; char *cp; } funny;

					der Mouse

			uucp: mouse at mcgill-vision.uucp
			arpa: mouse at larry.mcrcim.mcgill.edu



More information about the Comp.lang.c mailing list