safe to delete null pointer?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Songling

    #1

    safe to delete null pointer?

    Hi gurus,

    Just learnt from my co-worker that it's safe to delete a null pointer. I
    tried it on sun box
    (and linux), nothing bad happens. So it seems to be true. But does it apply
    to all platforms?

    Also if I delete a pointer twice, and don't nullify the pointer after the
    first delete, it's going
    to trap. If I do the nullify, no trap. Does it just confirm that it's safe
    to delete null pointer?

    Btw I ran my test on SunOS 5.8 and Linux 2.4.18-3.

    Thanks for your reply!

    Songling


  • Artie Gold

    #2
    Re: safe to delete null pointer?

    Songling wrote:[color=blue]
    > Hi gurus,
    >
    > Just learnt from my co-worker that it's safe to delete a null pointer. I
    > tried it on sun box
    > (and linux), nothing bad happens. So it seems to be true. But does it apply
    > to all platforms?
    >
    > Also if I delete a pointer twice, and don't nullify the pointer after the
    > first delete, it's going
    > to trap. If I do the nullify, no trap. Does it just confirm that it's safe
    > to delete null pointer?
    >
    > Btw I ran my test on SunOS 5.8 and Linux 2.4.18-3.
    >
    > Thanks for your reply!
    >
    > Songling
    >
    >[/color]
    Calling delete on a null pointer is a no-op -- and, by the standard, no
    problem. Of course, the fact that you're deleting a null pointer may
    indicate the existence of a bug in your program -- but not necessarily.

    HTH,
    --ag

    --
    Artie Gold -- Austin, Texas

    http://it-matters.blogspot.com http://www.cafepress.com/goldsays

    Comment

    • Sumit Rajan

      #3
      Re: safe to delete null pointer?

      Songling wrote:[color=blue]
      > Hi gurus,
      >
      > Just learnt from my co-worker that it's safe to delete a null pointer. I
      > tried it on sun box
      > (and linux), nothing bad happens. So it seems to be true. But does it apply
      > to all platforms?
      >
      > Also if I delete a pointer twice, and don't nullify the pointer after the
      > first delete, it's going
      > to trap. If I do the nullify, no trap. Does it just confirm that it's safe
      > to delete null pointer?[/color]


      Deleting a null pointer is safe. 5.3.5/2 of the Standard:

      "In either alternative, if the value of the operand of delete is the
      null pointer the operation has no effect."

      Regards,
      Sumit.
      --
      Sumit Rajan <sumit.rajan@gm ail.com>

      Comment

      • Stuart Gerchick

        #4
        Re: safe to delete null pointer?

        "Songling" <yangsong@norte lnetworks.com> wrote in message news:<coq847$p1 0$1@zcars0v6.ca .nortel.com>...[color=blue]
        > Hi gurus,
        >
        > Just learnt from my co-worker that it's safe to delete a null pointer. I
        > tried it on sun box
        > (and linux), nothing bad happens. So it seems to be true. But does it apply
        > to all platforms?
        >
        > Also if I delete a pointer twice, and don't nullify the pointer after the
        > first delete, it's going
        > to trap. If I do the nullify, no trap. Does it just confirm that it's safe
        > to delete null pointer?
        >
        > Btw I ran my test on SunOS 5.8 and Linux 2.4.18-3.
        >
        > Thanks for your reply!
        >
        > Songling[/color]

        Deleting a null poiner is fine. It will have no effect and will behave as expected

        Comment

        Working...