Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!sri-spam!ames!oliveb!sun!gorodish!guy From: guy@gorodish.UUCP Newsgroups: comp.lang.c Subject: Re: Query: Implementation with non-zero NULL Message-ID: <20163@sun.uucp> Date: Tue, 2-Jun-87 00:21:59 EDT Article-I.D.: sun.20163 Posted: Tue Jun 2 00:21:59 1987 Date-Received: Thu, 4-Jun-87 01:48:10 EDT References: <158@delftcc.UUCP> <3673@gitpyr.gatech.EDU> <3675@gitpyr.gatech.EDU> Sender: news@sun.uucp Lines: 40 Keywords: C, NULL, portability Summary: That's more like it! > Correction - if(p) yields false if p = (char *) NULL In other words, constructs like if (p) *do* yield correct results, and PRIME's C implementation *is* correct. (Assuming that "if (!p)" yields *true* if is a null pointer.) BIG difference! > Also, if(p != 0) also yields false. In other words, "if (p)" and "if (p != 0)" (and "if (p != NULL)") *are* the same. This is as it should be; those three constructs mean the same thing in C, and should all yield true iff "p" is not a null pointer. > The 0 is cast to (char *). Actually, the 0 is *coerced* to (char *); it is only *cast* to "char *" if you write "(char *)0". Casting is one way of generating a coercion, but it isn't the only way. In this case, the compiler knows that one operand of the "==" is a pointer, and the other is a constant 0, so it knows that it must coerce the constant 0 to a null pointer value of the appropriate type; no cast is necessary. > The value of 0x60000000 is correct. If you do a union with a long and > compare the long with zero (0), they will not be equal. Also, since in > some modes a pointer may be 48 bits, you would only get the first 32 bits > in the union. I presume "the value of 0x60000000 is correct" means "that is the bit pattern stuffed into a null pointer", not "NULL is #defined to be 0x60000000". Both of the behaviors you describe are perfectly legitimate, and permissible in a C implementation. Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com