freeing a null pointer

后端 未结 7 1033
天涯浪人
天涯浪人 2020-12-09 14:52

What happens inside memory if we try to free a pointer which is pointing to NULL? Is that ever valid?

Why does it not show any warning/error messages?

7条回答
  •  难免孤独
    2020-12-09 15:18

    What happens inside memory if we try to free a pointer which is pointing to NULL. is that ever valid?

    Nothing.

    why does it not show any warning/error messages?

    First, the behaviour is valid by definition, so no error or warning needs to be issued.

    Second, a pointer is pointing to NULL at runtime. How should a warning or error message be displayed, if at all? Imagine that you are playing a game called Kill the Zombie and while two of these beings are attacking you, a popup error message appears, saying: "Warning, NULL pointer freed."

提交回复
热议问题