pointer checking

Jan Wolter janc at crim
Tue Feb 23 01:10:55 AEST 1988



In article <325 at halley.UUCP> bc at halley.uucp (Bill Crews) writes:
> All right, I know and I am sure most of you out there know that Jan is
> supplying us with incorrect information in this message.  [...]  If you
> really don't understand why he (she?) is wrong, please REPLY to me, read
> K&R CAREFULLY, or consult your local guru.  Thanks.

> In article <779 at zippy.eecs.umich.edu> janc at palam.eecs.umich.edu (Jan Wolter) writes:
>
> >NULL is a pointer with an illegal value.  In some architectures, the address
> >0 is a perfectly reasonable address, so it is concievabale that someone might
> >set up a system with NULL defined as ((char *) -1), or some such.
>                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> If it does, it is DEAD WRONG!  The 0 is interpreted by the COMPILER and by the
> LIBRARY, NOT by the machine!  NULL is NOT an ADDRESS!

I might suggest that as a third alternative, people who don't understand this
might read the next sentance in my response quoted above.  The response says:

> NULL is a pointer with an illegal value.  In some architectures, the address
> 0 is a perfectly reasonable address, so it is concievabale that someone might
> set up a system with NULL defined as ((char *) -1), or some such.  However,
> I've never heard of anyone doing that, and, in fact, it would be contrary
> to K&R's definition of C.

In the future I will take care to state my facts with plenty of CAPS and
exclaimation points so that Bill will not overlook them and proclaim my
idiocy so stridently over the net.

I can claim little expertise in what is correct C, but I do know what is
portable.  Bill's suggestion of casting NULL as (void *) is a dubious one,
as many older compilers do not support the void type at all, or just do
#define void int.  I'm am not familiar with any system in which it is
necessary to type cast NULL in argument lists.  I don't know on what basis
Bill says NULL is not a pointer (K&R says nothing to suggest that) but I
know code that treats it as such is very portable.

Bill claims that this has been discussed before.  I would certainly not want
to say anything on the net that is not new.  I enter this here only to correct
the misquote.  Follow-ups should go to comp.lang.c.  Thank you for your
patience,

				Jan Wolter
				janc at crim.eecs.umich.edu



More information about the Comp.sources.bugs mailing list