[fdo-dev] Checking new'ed pointers for NULL

Greg Boone greg.boone at autodesk.com
Mon Aug 28 11:42:42 EDT 2006

Why do you advocate not to test pointers for NULL before calling delete

-----Original Message-----
From: Mateusz Loskot [mailto:mateusz at loskot.net] 
Sent: Monday, August 28, 2006 11:09 AM
To: dev at fdo.osgeo.org
Subject: Re: [fdo-dev] Checking new'ed pointers for NULL

Pierre Dalcourt wrote:
> Hi Mateusz,
> I think most of us agree with you.  The code that checks for a new
> operator returning NULL is either old code or code that was written by
> developers (including myself) before they realized that the new
> on modern compilers would never actually return NULL.  :-)  However,
> code that does the extra check is usually not harmful in itself so it
> may not be worth spending the extra effort to remove them unless you
> happen to be working on those files... 

I see and I agree, though for me this redundant tests make it
harder to read and analyze the code, especially when function bodies
are >100 lines long.

So, to summary this thread:
- it's OK to to not to test pointers for NULL after allocation with new
- it's OK to not to test pointers for NULL before calling delete

If there are no objections, I'm following those rules in my code for

Mateusz Loskot

To unsubscribe, e-mail: dev-unsubscribe at fdo.osgeo.org
For additional commands, e-mail: dev-help at fdo.osgeo.org

More information about the Fdo-internals mailing list