Caution for those considering MSC 5.0
Eric K. Bustad
ekb at ho7cad.ATT.COM
Thu Feb 18 00:29:00 AEST 1988
In article <620 at viper.Lynx.MN.Org>, john at viper.Lynx.MN.Org (John Stanley) writes:
> In article <11754 at brl-adm.ARPA> PEPRBV%CFAAMP.BITNET at husc6.harvard.EDU (Bob Babcock) writes:
> .......
> >The manual seems to indicate that only initialized global
> >data will go here, but isn't all global data implicitly
> >initialized to zero if not otherwise specified?
>
> It's true on "many", but not all systems. Rule of thumb is NEVER
> assume any UN-initialized variable contains zero (or NULL)... If you
> haven't explicitly put something into a variable, assume it's set to
> a random value or the constant most likely to cause your procedure to
> bomb....
Actually, K&R says on page 198: "Static and external variables which are
not initialized are guaranteed to start of as 0". If a compiler does not
arrange for this to happen, then it is not a C compiler. As a matter of
style, however, I agree with John that one should explicitly initialize
any variable if your code makes any use of its initial value.
As for how MSC 5.0 handles "uninitialized" globals, I imagine that it is
doing the same thing as all of the C compilers I've ever used. All of the
static variables which are implicitly initialized to zero are placed in a
separate section called BSS. Only the size of this section needs to be
stored in the object file, saving mucho disk space.
= Eric Bustad
More information about the Comp.lang.c
mailing list