Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ll-xn!husc6!diamond.bbn.com!mlandau From: mlandau@Diamond.BBN.COM (Matt Landau) Newsgroups: comp.lang.c Subject: Re: Query: Implementation with non-zero NULL Message-ID: <6255@slate.BBN.COM> Date: Mon, 1-Jun-87 12:02:58 EDT Article-I.D.: slate.6255 Posted: Mon Jun 1 12:02:58 1987 Date-Received: Wed, 3-Jun-87 00:56:43 EDT References: <158@delftcc.UUCP> <1070@viper.Lynx.MN.ORG> Reply-To: mlandau@Diamond.BBN.COM (Matt Landau) Organization: BBN Laboratories, Inc., Cambridge, MA Lines: 42 Keywords: C, NULL, portability Summary: "Unitialized statics are initialized to 0" - RTFK&R In comp.lang.c (<1070@viper.Lynx.MN.ORG>), john@viper.UUCP (John Stanley) writes: >In article <158@delftcc.UUCP> henry@delftcc.UUCP (Henry Rabinowitz) writes: > > > >Are static pointers initialized to all bits zero or to the null value > >(as in ANSI spec)? > > > > If, you're refering to an initialized static, it's whatever you >specify. If, on the other hand, you're refering to an UN-initialized >static pointer, the answer is a resounding "Neither!".... An un- >initialized variable is just that. It can initialy hold literaly >-any- value that variable can possibly hold. You should never assume >anything about any variable until you've set it. Once more, with feeling: STATIC VARIABLES THAT ARE NOT EXPLICITLY INITIALIZED ARE INITIALIZED TO ZERO BY DEFAULT. Take a look at the C Reference Manual, section 8.6, paragraph 3, which you should find on page 198 of the venerable K&R. It says this: Static and external variables which are not initialized are guaranteed to start off as 0; automatic and register variables which are not initialized are guaranteed to start off as garbage. The November 1985 draft proposed ANSI standard for C (section C.5.6) says this about the subject: An object that has static storage duration may be initialized by constant expressions only. If such an object is not initialized explicitly, it is initialized implicitly as if every scaler member were assigned the integer constant zero. More recent versions of dpANS may have changed the wording, but the behavior is deeply embedded in the definition of the C programming language. My apologies for going on at such length about such an obvious point, but this is the third time and the last few days that I've seen someone in comp.lang.c claim that *static* variables aren't initialized to anything. -- Matt Landau "Waiting for a flash of enlightenment mlandau@diamond.bbn.com in all this blood and thunder..."