Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!dciem!nrcaer!cognos!jimp From: jimp@cognos.uucp (Jim Patterson) Newsgroups: comp.lang.c Subject: Re: Query: Implementation with non-zero NULL Message-ID: <836@cognos.UUCP> Date: Thu, 4-Jun-87 12:49:20 EDT Article-I.D.: cognos.836 Posted: Thu Jun 4 12:49:20 1987 Date-Received: Fri, 5-Jun-87 04:42:11 EDT References: <158@delftcc.UUCP> <1070@viper.Lynx.MN.ORG> Reply-To: jimp@cognos.UUCP (Jim Patterson) Organization: Cognos Incorporated, Ottawa, Canada Lines: 50 In article <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!".... I won't deny that there may be some (non-conforming) C compilers that don't always initialize statics, or that in some environments it's costly to require that they be initialized, but it's quite clear in both K&R and in the ANSI C draft that ALL statics be initialized. Kierneghan & Ritchie, in "The C Programming Language", 1978 (generally regarded as the definitive specification of the C language prior to ANSI's involvement) state in section 4.9 (page 82) that "In the absence of explicit initialization, external and static variables are guaranteed to be initialized to 0". Section 8.6 of the reference manual (page 198) back this up; "Static and external variables which are not initialized are guaranteed to start off as 0". ANSI C has maintained this guarantee; in section 3.7.2 of the May 15, 1987 draft (page 73) an object defined outside of a function of either static or with no storage class specifier and no initializer is termed a "tentative definition". The section goes on to state "If no subsequent definition is encountered, the first tentative definition is taken to be a definition with initializer equal to 0". That, however, doesn't answer Mr. Rabinowitz's question. There is some additional clarification in the ANSI draft (this time from July 6, 1986; I'm afraid I don't have a more current copy of the relevant pages). This is in section 3.5.6 on Initialization (page 61): "If an object that has static storage duration is not initialized explicitly, it is initialized implicitly as if every member that has arithmetic type were assigned 0 and every member that has pointer type were assigned a null pointer constant". (If someone has a more up to date complete copy of the draft, perhaps you could confirm if this has changed; I don't believe it has). So, if the compiler is ANSI-conforming it should initialize pointers to null pointer constants, not 0. If it isn't ANSI-conforming, who knows? If the static pointer is in a union, then obviously there are problems. -- Jim Patterson Cognos Inc.