Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ecr2.UUCP Path: utzoo!hcrvax!ecrhub!ecr2!peterc From: peterc@ecr2.UUCP (Peter Curran) Newsgroups: net.lang.c Subject: Re: Re: how has C bitten you? (Really, Message-ID: <142@ecr2.UUCP> Date: Wed, 11-Sep-85 08:04:46 EDT Article-I.D.: ecr2.142 Posted: Wed Sep 11 08:04:46 1985 Date-Received: Fri, 13-Sep-85 07:29:14 EDT References: <259@watmum.UUCP>, <30000012@ISM780.UUCP>, <5938@utzoo.UUCP> Organization: Emerald City Research Inc., Toronto Lines: 30 Although the topic of Null pointers has been beaten to death many times, there is one point that I have never seen discussed. External variables are to be initialized to 0, according to the C Reference Manual (I don't have a copy of K&R handy, but I'm pretty sure it says the same thing.) These means that integers get 0, and pointers get NULL. (I don't know whatis supposed to happen to variables for which 0 is not valid - what really happens is they get 0 anyhow, of course). Since this includes all variables not explicitly initialized, it includes unions. It is hard to imagine an implementation of this that allows a block of memory representing simultaneously one or more pointers and one or more integers to be initialized correctly unless the bit pattern for a null pointer is identical to the bit pattern for a 0 integer of the same size (assuming one exists - otherwise concatenations of integers, or whatever else is required). I can think of at least two ways it could happen. First, I believe a compiler is free to treat 'union' as equivalent to 'struct' - i.e. ignore the intended overlaying of memory. It could then initialize the two sets of variables entirely independently. Second, I can imagine some form of tagged memory architecture in which the tags are only used in conjunction with instructions that use the memory as an address, so the non-tag (i.e. the integer) is zero, but the entire location (including the tag) is non-zero. I don't know enough about tagged memory architectures to pursue this very far, but it seems too complex to be really credible. Therefore, unless you accept a brain-damaged compiler that treats 'union' as equivalent to 'struct,' it seems hard to avoid the conclusion that C requires that the bit-pattern for a "null" pointer be identical to the bit pattern of "(int) 0" (except possibly in length).