Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!decvax!genrad!mit-eddie!godot!ima!ISM780B!jim From: jim@ISM780B.UUCP Newsgroups: net.lang.c Subject: Re: Must a NULL pointer be a 0 bit patte Message-ID: <104@ISM780B.UUCP> Date: Sat, 3-Nov-84 12:30:55 EST Article-I.D.: ISM780B.104 Posted: Sat Nov 3 12:30:55 1984 Date-Received: Sun, 4-Nov-84 04:43:27 EST Lines: 54 Nf-ID: #R:wjh12:-52900:ISM780B:25500062:000:2288 Nf-From: ISM780B!jim Nov 1 19:02:00 1984 >Three comments about non-zero NULL: > >1. Because of implicit comparison with zero, as in "while(p)s;", this idea >is cannot be implemented simply by changing stdio.h to read >#define NULL ((char*)0x87654321) I think you have misunderstood. There is no intention to change the definition of NULL. The changes are in the compiler, to interpret the constant "0" as different from all zero bits. Thus, register char *p = 0; would compile into l regp,=x'87654321' Under no circumstances does "while(p)" have semantics different from "while(p != 0)" in C. >2. In making changes to the compiler, this must remain zero: > (p = NULL , (int)p) The language spec does not guarantee it. In fact, it explicitly considers the result of this expression to be implementation-dependent. >Also, for every declared "var", this must remain one: > (p = &var , (int)p != 0) Ditto. In fact, regardless of the handling of NULL pointers, this expression may yield zero on machines with ints smaller than pointers, if the low-order bits of &var are zero. All of this has been discussed here before. >3. The issue of how a union can be set to zero was handled properly by the >correspondent who said the first member is initialized to zero. Statements like "so and so is right" or "I am for X" without analysis and argument are rather arrogant. If you think it is right say why, and refute other positions (such as that it may be desirable to initialize different members of different instances of the same union). I have yet to see an argument *for* always initializing the first member, other than "all the other methods have problems". Enumerate the other methods; state their problems. I suggest that if an initializer of a union has no explicit cast, it be converted to the type of the first member, otherwise it has an explicit content which should become the content of the union, provided it is type-compatible with at least one member of the union. The default case guarantees that this is at least as powerful as "initialize first member". It is unambiguous, it is complete if it is recognized that (char *)"abc" and (char [])"abc" produce different "values", and it is compatible in form with the existing language. -- Jim Balter, INTERACTIVE Systems (ima!jim)