Is it safe to #define NULL nullptr?

前端 未结 6 860
囚心锁ツ
囚心锁ツ 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 07:07

    No. You're not allowed to (re)define standard macros. And if you see

    #define NULL 0
    

    at the top of any file other than a standard header (and even there, it should be in include guards, and typically in additional guards as well), then that file is broken. Remove it.

    Note that good compilers will typically define NULL with something like:

    #define NULL __builtin_null
    

    , to access a compiler builtin which will trigger a warning if it is used in a non-pointer context.

提交回复
热议问题