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

Mateusz Loskot mateusz at loskot.net
Mon Aug 28 12:19:01 EDT 2006


Greg Boone wrote:
> Why do you advocate not to test pointers for NULL before calling delete
> operator?

Because of:
- C++ Standard/ 5.3.5 Delete / 2
- delete does nothing if its operand == 0, in other words when called
with 0 (null pointer), it has no effect
- C++ language guarantees delete p will do nothing if p is null-pointer
- testing for NULL is redundant and forces reader to analyze 2 x more
code than it's necessary
- it does not generate redundant CPU instructions, what may introduce
better performance when deallocating elements of big collection
- it may save programmer's time and keyboard ,-)

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




More information about the Fdo-internals mailing list