I must admit this null checking of mine is also an old school left-over...

On Tue, Oct 2, 2012 at 5:16 PM, David Chapman <[email protected]> wrote:
> On 10/2/2012 7:33 AM, Patrick J. LoPresti wrote:
>>
>> On Tue, Oct 2, 2012 at 5:55 AM, jody <[email protected]> wrote:
>>>
>>>
>>> ---------------------------------
>>> void CellGrid::destroyGrid() {
>>>
>>>      if (m_apCells != NULL) {
>>>          for (coord j = 0; j < m_iNumCells; j++) {
>>>              if (m_apCells[j] != NULL)  {
>>>                  delete m_apCells[j];
>>>              }
>>>          }
>>>          delete[] m_apCells;
>>>      }
>>>
>>>    //.... other stuff unrelated to m_apCells
>>> }
>>
>> This is not related to your problem, but...  In C++ -- all versions
>> ever, standard or otherwise -- calling "delete" on a NULL pointer is
>> guaranteed to be a no-op.  So there is never a need to check for NULL
>> before calling "delete".  Doing so makes your code run slower, makes
>> it harder to read, and makes the reader wonder whether the author
>> simply does not know C++ or is trying to work around some obscure bug
>> in some compiler.
>>
>>   - Pat
>>
>
> It wasn't so obscure 20 years ago - programs compiled with Zortech C++ would
> crash if you called a virtual destructor for a NULL pointer.  That wasn't
> fixed for a couple of versions.  Fortunately, all C++ compilers of which I
> am aware today handle this properly and the NULL check is truly redundant.
> But I still find "can't delete 0 in Zortech" comments in some of my oldest
> C++ code.
>
> And now back to your regularly scheduled programming...
>
> --
>     David Chapman      [email protected]
>     Chapman Consulting -- San Jose, CA
>     Software Development Done Right.
>     www.chapman-consulting-sj.com
>

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to