On Mon, Jan 29, 2001 at 01:16:13AM +0100, Matthias Buelow wrote:
> Alexander Mai <[EMAIL PROTECTED]> writes:
> >If you don't add the explicit initialization, so I would assume that
> >on runtime the program has to dig out what kind of variable it is
> >and then assign the 0 value. Isn't there a trade-off between 
> 
> I was under the impression that for standards compliance it is sufficient
> that the memory bytes are initialized to zero, and because of that you
> cannot rely on, for example, static pointer variables being initialized
> to 0 (NULL) because as we all know, 0 in pointer context may be something
> different than all bits cleared.  (I'd say the same applies to floating
> point variables so you probably can only rely on integer and character
> types to be properly initialized to 0.)  I'm not a language lawyer, though,
> and unfortunately don't have the C89/C99 Standard text at hand so if
> somebody here knows The Truth, I'd like to be enlightened on this topic.


Citing from my C9X draft copy:

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:
     - if it has pointer type, it is initialized to a null pointer;
     - if it has arithmetic type, it is initialized to (positive or unsigned) zero;
     - if it is an aggregate, every member is initialized (recursively) according to 
these rules;
     - if it is a union, the first named member is initialized (recursively) according 
to these
         rules.
 
> I don't expect the C runtime to do any initializing for bss variables,
> since the OS already provides cleaned (i.e. all bytes 0) pages on
> allocation (well, maybe PC compiler runtimes on pathetic legacy systems
> like MS-DOS do this themselves but that doesn't matter here anyways).
> 
> mkb

Arguments based on operating system standards/ architecture/ etc.
are not helpful here - since one shouldn't rely on.
The lower the requirements we have the better it is.

-- 
Alexander Mai
[EMAIL PROTECTED]

Reply via email to