Subject: Re: Question about initializing variables
To: Joao Carlos Mendes Luis <firstname.lastname@example.org>
From: Chris G Demetriou <Chris_G_Demetriou@UX2.SP.CS.CMU.EDU>
Date: 04/08/1996 21:15:59
> // 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...)
> Just remember that this is not true on all operating systems. Once
> I had a program that worked perfectly on NetBSD but did not work on
> SunOS 4.1.2. The problem: non-initialized variables that should have
> zeros as value...
What does "should" mean?
"Should," as in the programmer _should_ have initialized them, or
"should," as in the run-time environment or compiler should have
Automatic variables are examples of the former.
Uninitialized global variables are examples of the latter; they are
_defined_ to have a value of zero.
> Surelly not a problem if intended to use only in internal programs.
> // In other words, as charles said: "It's not a bug."
> Personally, I call it programming discipline: "NEVER leave a variable,
> any variable, without initialization !"
Indeed, not specifying a value for a global is _not_ leaving it
uninitialized, it's defined to be initializing it to zero.
_I_ call bad programming discipline not knowing when variables are
required to be initialized... 8-)