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

Mateusz Loskot mateusz at loskot.net
Mon Aug 28 11:08:49 EDT 2006


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 operator
> 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
operatir
- it's OK to not to test pointers for NULL before calling delete operator.

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

Cheers
-- 
Mateusz Loskot
http://mateusz.loskot.net




More information about the Fdo_dev mailing list