Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site watmath.UUCP Path: utzoo!watmath!kpmartin From: kpmartin@watmath.UUCP (Kevin Martin) Newsgroups: net.lang.c Subject: Re: Must a NULL pointer be a 0 bit pattern? Message-ID: <9485@watmath.UUCP> Date: Fri, 19-Oct-84 14:15:33 EDT Article-I.D.: watmath.9485 Posted: Fri Oct 19 14:15:33 1984 Date-Received: Sun, 21-Oct-84 11:30:44 EDT References: <6542@mordor.UUCP> <5272@brl-tgr.ARPA> <196@rlgvax.UUCP> <529@wjh12.UUCP> Reply-To: kpmartin@watmath.UUCP (Kevin Martin) Organization: U of Waterloo, Ontario Lines: 39 > The "proof" goes as follows: consider this external declaration: > > union { > char * p_member; > double f_member; > char c_member[COVERS_P_AND_F]; > } implicitly_initialized_to_zero; > >It seems to me that K&R guarantees that, when the program begins >execution, p_member, f_member and c_member are guaranteed to be >zero simultaneously, and the only way to do it is to make them all a >zero bit pattern. I don't have my manual with me--can anyone try to >poke holes in this? It may be that the K&R wording isn't rigorous >enough, and that my proof "falls to the ground". It is indeed the case that K&R isn't very rigorous on that point. I have always read "guaranteed to start off as 0" as denoting the bit pattern, rather than the interpretation of the bit pattern in any particular type. I would prefer that uninitialized variables be just that: uninitialized, but initializing to the *bit pattern* of zero bits is second best. > ANSI C deals with this by giving a rule for explicit initialization >of unions: the first member is the one that is initialized. Implicit >initialization can use the same rule, meaning that in the above example, >only p_member would be guaranteed to start out as a zero (null) value. > Sam Kendall {allegra,ihnp4,ima,amd}!wjh12!kendall As for explicit initializers, I certainly don't see a good reason for picking the first element of a union; it is very likely that in two variables of the same union type, I would want the initialization to occur to two different elements. It would be far more advantageous to add a method of explicitely naming the union element you want to hit. As a side effect of the required syntax, you could also initialize array and struct elements in any desired order. Unfortunately, this would require additions to the language, which is not what the committee is out to do, etc. etc. Kevin Martin, UofW Software Development Group