Need help on Ptr

Derek Elkins ddarius@hotpop.com
Thu, 15 May 2003 16:29:27 -0400


On Thu, 15 May 2003 22:07:56 +0200
Christian Buschmann <white_russian@gmx.net> wrote:

> Hal Daume III wrote:
> > Why not:
> > 
> >   isNullPtr = (==nullPtr)
> > 
> > ?
> Oh sure....sorry....
> i tried this before, but i had a small confusion with my
> type-signatures in my program and it didn't work. Now i fixed my
> signatures and its working....
> But there is one more (small) question:
> If i am using the "peekCString" function with a null-pointer my
> program crashes, because the peekCString function is trying to read a
> String from an illegal address. But is this normal behaviour of this
> function? Shouldn't it check for a null-pointer and then return an
> empty String, raise an exception or do something else than crashing my
> program?
> 
> Oh, and my compiler is ghc-5.04.2 on linux-2.4.20
> 
> thx
>    christian

It DEFINITELY should NOT return an empty string.  Further, I imagine it
would be pretty painful to check for a nullPointer every time you could
use it (i.e. in this case and other cases, it would be arbitrary to just
usi it in this case.)  I'd rather it be a fast and small as possible. 
If I really want the checking it is trivial to write it myself.
checkedPeekCString p | isNullPtr p = ioError uhoh
                     | otherwise   = peekCString p