Uninitialized global data (was Re: Global variables) 
Author Message
 Uninitialized global data (was Re: Global variables)

To get back to the original question (do we ever do that here?)

From someone whose attribution has since vanished:

Quote:
>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?

I believe that global data initialized to zero go into a special
segment called "bss".  What it stands for is beyond me.  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 meant to save space in the executable.

Corrections welcomed.  flames slightly less so.

--
Raymond Chen    UUCP: ...allegra!princeton!{phoenix|pucc}!rjchen


"Say something, please!  ('Yes' would be best.)" - The Doctor



Mon, 20 Jul 1992 17:28:00 GMT  
 Uninitialized global data (was Re: Global variables)

Quote:

>I believe that global data initialized to zero go into [the bss segment].
>... When the program is loaded, the loader allocates the requisite amount of
>space and initializes it to zero at runtime.

Close enough.  But this is a property of one particular implementation, not a
description of C in general.  Note also that if a floating-point zero or a
null pointer has some representation other than all-bits-zero, then any
floating or pointer object with static duration and no explicit initializer
would not be correctly handled by this gimmick.  (Unless you have a really
smart loader.)  The compiler is obliged to initialize it to a zero of the
appropriate type, which can (of course) be placed in the data segment along
with the explicitly initialized variables.

Quote:
>What [bss] stands for is beyond me.

Oh no.

Followups on this subtopic, please redirect to comp.misc and put "bss" in the
subject line so I can kill it.  I hope this doesn't get as bad as the "foo"
postings a while back.




Mon, 20 Jul 1992 05:21:00 GMT  
 Uninitialized global data (was Re: Global variables)

Quote:

>I believe that global data initialized to zero go into a special
>segment called "bss".  What it stands for is beyond me.

BSS means "Block Started by Symbol", and comes from an IBM7090 assembly
pseudo-op.
--
--------------------"Well, it looked good when I wrote it"---------------------
 Verbal: Dave Burton                        Net: ...!ihnp4!laidbak!daveb
 V-MAIL: (312) 505-9100 x325            USSnail: 1901 N. Naper Blvd.
#include <disclaimer.h>                          Naperville, IL  60540


Mon, 20 Jul 1992 14:36:00 GMT  
 Uninitialized global data (was Re: Global variables)

Quote:
> I believe that global data initialized to zero go into a special
> segment called "bss".  What it stands for is beyond me.  ...

'bss', I believe, comes from the early IBM assemblers. It stands for 'Block
Started by Symbol'. This was/is a pseudo op which reserves spaces in
the data area, used as in:

fred:   bss     12              // Reserve 12 bytes.

[Excuse the syntax if its wrong].

I presume that this pseudo op was present in the early PDP-7 & 11 assemblers as
well. (On the PDP-10, BLKZ or BLK was used).



Mon, 20 Jul 1992 17:17:00 GMT  
 Uninitialized global data (was Re: Global variables)

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

Quote:
> 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





Mon, 17 Aug 1992 05:06:00 GMT  
 Uninitialized global data (was Re: Global variables)

Quote:

>Could someone with access to the draft clear this up?

Without even looking it up, I can tell you that the default initial
values are required to be zeros of the right type.  Pointers would
have null pointer values, integer types all 0 bits (in effect), and
floating point data would have 0.0 even if the bit pattern required
for this is not all 0 bits.  On many implementations, filling BSS
with all-0 bytes will do the trick, but there are those that require
more elaborate initialization.


Mon, 17 Aug 1992 21:02:00 GMT  
 Uninitialized global data (was Re: Global variables)

Quote:
> ... 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;

It gets initialized as if by "funny.i = 0".  X3J11 says that initialization
of unions is by their first member.  (Please don't start another flame war
over this, we've been through it several times before.  X3J11 picked the
minimum solution that made the initial state of static unions well-defined,
a solution which had been used with some success by existing compilers.
Nobody disputes that it is ugly and inflexible; if you wish to propose a
better alternative, DON'T post it to the net -- implement it in your local
C compiler, use it for a couple of years, and then submit it to X3J11 when
the C standard comes up for revision.  Implementation and successful use
carries far more weight than words on paper.)
--

non-negotiable."  --DMR              | {allegra,ihnp4,decvax,utai}!utzoo!henry


Mon, 17 Aug 1992 17:30:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Global variable or not global variable

2. Global Variable's Data Missing......

3. Global Variable's Data Missing......

4. Global Variable's Data Missing......

5. static local variables vs global variables

6. Variables & Global Variables

7. global variables and external variables?

8. CONFLICT - Global Var of a .LIB Vs Global Var of a program which uses the LIB

9. To be Global or not to be Global??

10. Why is not possible to assign a global variable to another global variable..?

11. Global variable

12. global variables

 

 
Powered by phpBB® Forum Software