From: Richard Stamp
Newsgroups: comp.lang.c
Subject: Re: NULL vs Int 0
Date: Sun, 7 Feb 1999 16:57:20 -0000
Message-ID: <918407071.27444.1.nnrp-12.9e98ce80@news.demon.co.uk>
References: <79fckc$jc2$1@news1.mts.net> <79fdke$1r8$1@remarQ.com> <79ijbq$njb$1@nnrp1.dejanews.com> <36BD1771.7835@infi.net> <918393784snz@genesis.demon.co.uk>

Lawrence Kirby wrote in message <918393784snz@genesis.demon.co.uk>... >Null pointers work perfectly well on platforms where "address 0" can
>point to a valid object. However there is a reason for why a null pointer
>should compare equal to zero and that is that tests like if ()
>statements do the natural thing. Given that it makes sense for null
>pointer constants to be defined in a consistent way.

The reason people find this confusing (and it's clear that lots of people do find it confusing; I remember being very confused myself a while ago) is, I think, that 0 changes in meaning depending on the situation in which it's used.

Normally 0 means integer zero, but in some cases it means null pointer. It's natural to try to find a link between these and think of the null pointer as pointing to address 0, but as the FAQ makes clear this isn't a valid approach.

We're all familiar with operators changing their meaning according to context (the - operator behaving quite differently with pointers than with numbers, for example), but it's more surprising to see a constant acting that way.

Cheers,
Richard