From: tsaylor@ecst.csuchico.edu (Todd M. Saylor)
Subject: Re: Dereferencing NULL pointer?
Date: 1997/05/22 [thread overview]
Message-ID: <5m239e$ajk@charnel.ecst.csuchico.edu> (raw)
In-Reply-To: x7n2po7afl.fsf@hexadecimal.uoregon.edu
> Your example program is inherently wrong. A NULL pointer in ANSI C is
> (void *) 0 -- it's valid to cast 0 to any pointer type to get a NULL,
> and it's also valid to cast void * to any other pointer type; while
> "#define NULL ((void *) 0)" is commonly used, it is no longer necessary
> to use NULL as an pointer constant when you can use 0 instead. A ASCII
> NUL character (note the different spelling) is '\0'. You don't get a
> NUL character by dereference of a NULL pointer, because dereference of a
> NULL pointer is undefined -- some architectures allow it but could
> return any value whatsoever, while others generate SIGSEGV if you do it,
> so you should never depend on it being possible in a portable program.
> You need to read a C book, and so did the authors of the program you are
> porting. In the long run you will be much better off fixing the program
> to eliminate the bogus NULL references than you are trying to find a way
> to make it allowable on the architectures you port the program to. I've
> been through such messes already and most such NULL reference problems
> introduce many subtle bugs.
Correct? Yes.
Helpful? Not so much.
These things I already know, so I think I'll skip the advice to read a
C book. We are porting a "million line plus" application, not just a
single program, so what we are really hoping for is some way of treating
the NULL pointer as a pointer to a NUL character. This is the way it
ends up working on the other platforms we've used (yes, I know the results
are technically undefined, but many platforms have linker switches or other
tricks to allow this). Blame it on legacy code.
--
next prev parent reply other threads:[~1997-05-22 4:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-05-21 4:00 Dereferencing NULL pointer? Todd M. Saylor
1997-05-21 4:00 ` Steve VanDevender
1997-05-22 4:00 ` Todd M. Saylor [this message]
1997-05-23 4:00 ` Dan Pop
1997-05-28 4:00 ` Vikas Sontakke TOEM
1997-05-29 4:00 ` Craig Neth USG
1997-05-29 4:00 ` Craig Neth USG
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox