geigel@soleil.UUCP (Joe Geigel) (01/08/88)
I have a question for you all. Is NULL always equivalent to the value 0?
I know it is in many implementations of C but is it always defined to be so?
The reason being is that a friend of mine was using the following in
a routine of his:
if (ptr = strchr (str,'\')) {
.
.
.
}
I argued that although this may work in the C we are using (VAX-C), it
may not be totally portable to other systems.
I am correct in saying this? Any words of wisdom would be appriciated.
Thanks.
-- jogle
...!rutgers!soleil!geigel
jmg%smvl.decnet@GE-CRD.arpa
gwyn@brl-smoke.ARPA (Doug Gwyn ) (01/09/88)
In article <134@soleil.UUCP> geigel@soleil.UUCP (Joe Geigel) writes: > Is NULL always equivalent to the value 0? NULL is a macro #defined by <stdio.h> and occasionally other headers. It is whatever it is #defined to be! However, as we discuss in this newsgroup about once a year, the ways that it is intended to be used (as a generic null pointer constant) require that it be #defined to be just the integer constant 0, in pre-ANSI C, or either 0 or (void *)0 in ANSI C. Some implementations currently #define it as (char *)0, but whoever did that was operating under a misconception. > if (ptr = strchr (str,'\')) { This is, has been, and will continue to be a correct way to test for a null pointer. However, '\' is nonportable.