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. Advertisements

  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. Advertisements

  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. Advertisements

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:
    30,347
    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:
    4,077
    Mathieu Malaterre
    Aug 17, 2004
  3. Songling

    safe to delete null pointer?

    Songling, Dec 3, 2004, in forum: C++
    Replies:
    3
    Views:
    28,429
    Stuart Gerchick
    Dec 3, 2004
  4. Gabriel Rossetti
    Replies:
    0
    Views:
    1,844
    Gabriel Rossetti
    Aug 29, 2008
  5. Replies:
    1
    Views:
    552
    Brian Candler
    Aug 12, 2003
  6. Aredridel

    Not just $SAFE, but damn $SAFE

    Aredridel, Sep 2, 2004, in forum: Ruby
    Replies:
    19
    Views:
    536
  7. Farrel Lifson

    $SAFE =4 safe enough?

    Farrel Lifson, Aug 29, 2006, in forum: Ruby
    Replies:
    7
    Views:
    343
    Eric Hodel
    Aug 31, 2006
  8. John Nagle
    Replies:
    5
    Views:
    762
    John Nagle
    Mar 12, 2012
Loading...