Is it safe to #define NULL nullptr?

前端 未结 6 912
囚心锁ツ
囚心锁ツ 2021-02-02 06:38

I have seen below macro in many topmost header files:

#define NULL 0  // C++03

In all over the code, NULL and 0 are u

6条回答
  •  青春惊慌失措
    2021-02-02 06:55

    You shouldn't be defining it at all, unless you're writing your own version of ; it certainly shouldn't be in "many topmost header files".

    If you are implementing your own standard library, then the only requirement is

    18.2/3 The macro NULL is an implementation-defined C++ null pointer constant

    so either 0 or nullptr is acceptable, and nullptr is better (if your compiler supports it) for the reason you give.

提交回复
热议问题