Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!ames!oliveb!sun!gorodish!guy From: guy%gorodish@Sun.COM (Guy Harris) Newsgroups: comp.lang.c Subject: Re: pointer debate raging on... Message-ID: <17498@sun.uucp> Date: Mon, 27-Apr-87 23:41:27 EDT Article-I.D.: sun.17498 Posted: Mon Apr 27 23:41:27 1987 Date-Received: Wed, 29-Apr-87 05:26:20 EDT References: <149@sds.UUCP> <31@thirdi.UUCP> Sender: news@sun.uucp Lines: 57 Keywords: pointers, religion, sin, Ritchie, razor blades, etc. > As pointed out, environments where sizeof(int) != sizeof(char *) > require NULL to be define'd as ((char *)0) (or some variation on that > theme). Excuse me? On the contrary, it has been repeatedly pointed out that NOTHING requires that you define NULL in that fashion, and it has been pointed out several times that there are problems with defining it thus. I worked for several years on a machine where sizeof(int) != sizeof(char *), and where NULL was defined as 0, as it should be. Incorrect C programs did not work, but so what? Correct C programs worked correctly. Yes, it took some work to make some programs pass "lint", but you ended up with better programs afterwards; "lint" would sometimes even uncover bugs in those programs. This one counterexample is more than sufficient to refute the claim that definitions of NULL as something other than just plain old 0 is somehow "required" by such environments. > Unfortunately, this is not the end of this train of thought. > There is NO guarantee I am aware of that sizeof(char *) == > sizeof(struct foo *)! The lack of such a guarantee is the end of that train of thought, though. Defining NULL as (char *)0 is not sufficient for the general case. > For this reason (and to adhere to a local naming convention), we use a > specifically typed nil pointer for each and every type. Which means you can define NULL as 0 and not worry about it. > if (foo != fooNil) ... Which is clearly correct, > vs. > if (foo != NULL) ... Which just doesn't feel safe to me. But is clearly correct nonetheless. > This method has stood us in good stead (except when we have foolishly > violated it) in porting a source-level debugger to over 70 different > systems - not all of which were done by followers of the True Faith. Umm, err, it's not a matter of "faith", so the use of terms connoting religion is inappropriate and somewhat irritating here. K&R is quite clear on this matter; if somebody doesn't "believe in" K&R (or ANSI C), they're perfectly welcome to implement some language that does things otherwise, they're just not welcome to call it C. A number of the participants in this discussion seem to be of the opinion that there is no objective standard against which the correctness of various implementations or opinions about the language can be judged. This is simply not true. Others seem to be of the opinion that it is somehow impossible to make C work on a machine with pointers and "int"s of different sizes without defining NULL as 0. This is also not true.