Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!sri-spam!ames!ucbcad!ucbvax!decvax!decwrl!sun!gorodish!guy From: guy@gorodish.UUCP Newsgroups: comp.lang.c Subject: Re: pointer debate raging on... (LONG) Message-ID: <17446@sun.uucp> Date: Mon, 27-Apr-87 14:56:13 EDT Article-I.D.: sun.17446 Posted: Mon Apr 27 14:56:13 1987 Date-Received: Wed, 29-Apr-87 00:48:25 EDT References: <149@sds.UUCP> Sender: news@sun.uucp Reply-To: guy@sun.UUCP (Guy Harris) Organization: Sun Microsystems, Mountain View Lines: 41 >Again, this bias of mine comes with working with brain-damaged compilers >which do not correctly compare 32-bit pointers to 16-bit ints. Any compiler that thinks that it should be comparing a pointer to an "int" when confronted with if (charptr == 0) is *prima facie* wrong, regardless of whether pointers and "int"s are the same size. The problem is *not* that said compilers weren't properly comparing pointers and "int"s; the problem is that said compilers weren't coercing the 0 to (char *)0 and comparing pointers and pointers. >Applaud, applaud, applaud. John has correctly pointed out that >sizeof(pointer) == sizeof(int) is not the universal constant that >many people believe it to be. It is for this exact reason that >NULL should ***NOT*** be defined as 0. OK, now given that sizeof (char *) == sizeof (int *) is also not a tautology, what should NULL be defined as? (char *)0 won't cut it, nor will (int *)0. If you have function prototypes, function calls - in *most*, but not *all*, cases - will behave like other operators; the compiler will be able to properly coerce arguments (*or* complain if the coercion doesn't make any sense, which is why I like the idea of function prototypes *and* would prefer that compilers generate warning messages whenever a function is used and there is no prototype declaration or definition for that function in scope). Given this, as long as you remember to properly cast null pointers passed to functions like "execl", NULL can be defined as 0. If you don't have function prototypes, you can stick in the appropriate cast to coerce NULL into a null pointer of the proper type. Given this, NULL can be defined as 0, and probably should, since "lint" will not be happy about casting a "char *" into, say, an "int *".