Subject: Re: Question about initializing variables
To: Joao Carlos Mendes Luis <>
From: Waldi Ravens <>
List: tech-userlevel
Date: 04/09/1996 21:58:34
Joao Carlos Mendes Luis wrote:

>   Personally, I call it programming discipline: "NEVER leave a variable,
> any variable, without initialization !"

Fortunately, ANSI C guarantees that all objects, that have static
storage class, will always be initialised. In the absence of an
explicit initialiser, the default initialisers are either 0 (for
integer types), 0.0 (floating point types) or null (pointers).
The default initialiser for an array or structure is the recursive
default for each component; the default initialiser for a union is
the default for its first component.

As for objects of automatic storage class, I doubt whether it makes
sense to always include an explicit initialiser in the declaration.
It may be "programming discipline" to do so, but quite often there
won't be any usefull initialiser value. In those cases the explicit
initialiser will be, at best, misleading to the programmers that
have to maintain the code. Worse than that, those fake initialisers
might mislead the compiler and bug-tracking tools.