On Thu, 29 Jun 2000, Thomas Dickey wrote:
> > > remember whether the C standard requires static variables to be
> > > initialized to zero by the runtime environment...
> > They require it.
> 
> I'm told that AIX's compiler does not necessarily do this for uninitialized
> values...

That's curious, since it cannot conform to the C standard without doing so
(the implicit initialization to zero is mandatory), and IBM was a strong
supporter of the standard.  I would guess that this is a matter of either
old compilers or compilers which mistakenly default to providing a
non-standard C environment. 

Note a subtlety:  it's only *static* variables which get the implicit
initialization to zero.  Local variables of functions don't, although it
often happens by accident (since most kernels zero-fill newly-allocated
stack memory) and some buggy programs rely on it. 

> -- have also been told that pointers are not guaranteed by the standard to
>    be initialized to 0's.

The standard guarantees that static variables are initialized as if by the
assignment of a constant 0.  In the case of pointer variables, that means
they get initialized to a null pointer.  However, there is no promise that
the *representation* of the null pointer is all-bits-zero.

In a context where a pointer value is required, e.g. an assignment to a
pointer variable, the constant 0 gets *converted* to a null pointer, and
that conversion might involve an actual change of representation.  There
is enough type cheating in old programs that it's highly desirable for an
implementation to use all-bits-zero as the null-pointer representation,
but the standard does not actually require it. 

                                                          Henry Spencer
                                                       [EMAIL PROTECTED]

-
Linux-UTF8:   i18n of Linux on all levels
Archive:      http://mail.nl.linux.org/lists/

Reply via email to