Path: utzoo!utgpu!water!watmath!clyde!bellcore!decvax!ucbvax!pasteur!ames!umd5!trantor.umd.edu!chris From: chris@trantor.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Global variables (was Re: Caution for those considering MSC 5.0) Message-ID: <2302@umd5.umd.edu> Date: 16 Feb 88 10:49:14 GMT References: <11754@brl-adm.ARPA> <620@viper.Lynx.MN.Org> Sender: ris@umd5.umd.edu Reply-To: chris@trantor.umd.edu (Chris Torek) Organization: University of Maryland, College Park Lines: 33 >>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@viper.Lynx.MN.Org> john@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@mimsy.umd.edu Path: not easily reachable