自C ++ 11起,标准允许宏NULL
成为值为零的整数文字或类型为std::nullptr_t
的prvalue。
[任何标准库供应商决定将NULL
的定义从整数更改为nullptr
都很可能导致依赖C ++ 11之前代码的客户端损坏。
是否有任何主要实现(例如,GCC,Clang,MSVC)实际上将NULL
定义为nullptr
?或尽管有可能,但没有人这样做吗?
[libstdc++
relies on including stddef.h
,它通过以下方式定义stddef.h
:
NULL
[// <stddef.h>
//
#if defined (_STDDEF_H) || defined (__need_NULL)
#undef NULL /* in case <stdio.h> has defined it. */
#ifdef __GNUG__
#define NULL __null
#else /* G++ */
#ifndef __cplusplus
#define NULL ((void *)0)
#else /* C++ */
#define NULL 0
#endif /* C++ */
#endif /* G++ */
#endif /* NULL not defined and <stddef.h> or need NULL. */
#undef __need_NULL
libc++
:
does pretty much the same thing