[C++] Ce se intampla daca dam delete la un pointer NULL?

Despre limbajul de programare C++ si biblioteca standard STL (forum moderat)
Post Reply
User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

[C++] Ce se intampla daca dam delete la un pointer NULL?

Post by Ovidiu Cucu » 30 Jan 2009, 13:02

Intrebare: Ce se intampla daca dam delete la un pointer NULL?
Raspuns: Nu se intampla nimic.

NOTA: Teste gen

Code: Select all

    if(p != 0)
    {
        delete p;
    }
in cele mai multe cazuri nu fac decat sa complice codul.
Standardul de C++ spune urmatoarele:
...if the value of the operand of delete is the null pointer the operation has no effect.
Deci, testul de NULL dinaintea lui delete, nu are rost.

Resurse
  • ISO/IEC 14882:2003 - 5.3.5 Delete


Next FAQ >>



Post Reply