Subject: Re: Question about initializing variables
To: Chris G Demetriou <>
From: Erik Bertelsen <>
List: tech-userlevel
Date: 04/09/1996 09:04:48
On Mon, 8 Apr 1996, Chris G Demetriou wrote:

.. >  > 	/* counters */
.. >  > 	long ntransmitted = 0;

.. >  > 	main(argc, argv)
.. >  > 	...
.. >

.. BSS variables are defined to have a starting value of zero.
.. (I forget where that's defined; maybe ANSI... in any case, where it
.. is, they're most likely called unintialized globals, or something...)

The C standard (ISO 9899) has the following wording in section 6.5.7
about initialization:

"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, it is initializes
implicitly as if every member that has arithmetic type were assigned
0 and every member that has pointer type were assigned a null pointer

In the example above ntransmitted is defined outside main (and I take
that to mean that it defined outside of any other function), and therefore
has static scope. Therefore it is required to be initialized to 0 by
a runtime environment conforming to standard C.

When you give counter-examples, please be specific when you talk about
SunOS: SunOS 4 does not provice a Standard C environment, but SunOS 5
does (at least I have not spotted any deviations).

Erik Bertelsen.