Global variables (was Re: Caution for those considering MSC 5.0)

Chris Torek chris at trantor.umd.edu
Tue Feb 16 20:49:14 AEST 1988


>>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?

In article <620 at viper.Lynx.MN.Org> john at viper.UUCP (John Stanley) writes:
>  It's true on "many", but not all systems.

It is false only on *broken* systems.  If you have such a broken
system, complain.

All[*] global and static data in C is either initialised by the programmer
(in which case, if it does not have the proper value on startup, the
compiler is broken) or not initialised by the programmer (in which case,
if it does not have zero values[**] on startup, the compiler is broken).

>Rule of thumb is NEVER assume any UN-initialized variable contains
>zero (or NULL)...

You can do this if you wish.  Remember, *automatic* variables are
indeed full of trash.

----
[*] Note that unions cannot be initialised at all in pre-dpANS C,
hence these are currently an exception.

[**] values equivalent to those if the construct had been set to
all zero values, i.e., `static int k' and `static int k = 0' are
to be the same; `static char *s' and `static char *s = 0' are ALSO
to be the same, and s will be ==0 and ==NULL and ==(char *)NULL.
-- 
In-Real-Life: Chris Torek, Univ of MD Computer Science, +1 301 454 7163
(hiding out on trantor.umd.edu until mimsy is reassembled in its new home)
Domain: chris at mimsy.umd.edu		Path: not easily reachable



More information about the Comp.lang.c mailing list