Is 'delete [] NULL ;' safe ?

Discussion in 'C++' started by qazmlp, Jul 29, 2003.

  1. qazmlp

    qazmlp Guest

    Say, ptr=0 / ptr=NULL.

    delete ptr; //is safe

    // Is
    delete [ ] ptr; // also safe ?
     
    qazmlp, Jul 29, 2003
    #1
    1. Advertising

  2. "qazmlp" <> wrote in message
    news:...
    > Say, ptr=0 / ptr=NULL.
    >
    > delete ptr; //is safe
    >
    > // Is
    > delete [ ] ptr; // also safe ?


    Yes.
    --
    jb

    (replace y with x if you want to reply by e-mail)
     
    Jakob Bieling, Jul 29, 2003
    #2
    1. Advertising

  3. On 29 Jul 2003 09:19:43 -0700, (qazmlp) wrote:

    >Say, ptr=0 / ptr=NULL.
    >
    >delete ptr; //is safe
    >
    >// Is
    >delete [ ] ptr; // also safe ?


    delete or delete[] of 0 is safe.

    NULL may or may not be safe depending on the definition; if it is
    the standard NULL from e.g. [cstddef] then yes, that's also safe.
     
    Alf P. Steinbach, Jul 29, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    26,687
    Mike Schilling
    Mar 29, 2006
  2. Mathieu Malaterre

    delete NULL, what about delete[] NULL

    Mathieu Malaterre, Aug 17, 2004, in forum: C++
    Replies:
    2
    Views:
    3,831
    Mathieu Malaterre
    Aug 17, 2004
  3. Songling

    safe to delete null pointer?

    Songling, Dec 3, 2004, in forum: C++
    Replies:
    3
    Views:
    27,905
    Stuart Gerchick
    Dec 3, 2004
  4. Gabriel Rossetti
    Replies:
    0
    Views:
    1,326
    Gabriel Rossetti
    Aug 29, 2008
  5. Replies:
    1
    Views:
    339
    Brian Candler
    Aug 12, 2003
Loading...

Share This Page