C++ 是否有任何主要的C++;实现是否将“NULL”定义为“nullptr”?

C++ 是否有任何主要的C++;实现是否将“NULL”定义为“nullptr”?,c++,c++11,null,c++-standard-library,nullptr,C++,C++11,Null,C++ Standard Library,Nullptr,自C++11以来,该标准允许宏NULL要么是值为零的整数文本,要么是std::nullptr\t类型的prvalue 任何标准库供应商决定将其NULL的定义从整数更改为nullptr,这很可能会导致依赖C++11之前版本代码的客户中断 是否有任何主要实现(如GCC、Clang、MSVC)实际将NULL定义为nullptr?或者,尽管可能,没有人这样做?libstdc++,它以以下方式定义NULL: // <stddef.h> // #if defined (_STDDEF_H) ||

自C++11以来,该标准允许宏
NULL
要么是值为零的整数文本,要么是
std::nullptr\t
类型的prvalue

任何标准库供应商决定将其
NULL
的定义从整数更改为
nullptr
,这很可能会导致依赖C++11之前版本代码的客户中断

是否有任何主要实现(如GCC、Clang、MSVC)实际将
NULL
定义为
nullptr
或者,尽管可能,没有人这样做?

libstdc++
,它以以下方式定义
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

微软的
STL
也:


ICC19.0.1
的简单测试也表明
NULL
不被定义为
nullptr

#include <type_traits>
#include <cstddef>

static_assert(!std::is_same<decltype(NULL), std::nullptr_t>::value, "");
static_assert(!std::is_same<decltype(NULL), int>::value, "");
static_assert(std::is_same<decltype(NULL), long>::value, "");
#包括
#包括
静态断言(!std::is_same::value,“”);
静态断言(!std::is_same::value,“”);
静态断言(std::is_same::value,“”);

您可以为您的工具链确定这一点(事实上,这三个工具链都是如此)。您在获取此信息时是否遇到了一些实际问题?如果将
NULL
0L
更改为
NULL ptr
会破坏您的代码,那么您的代码总是会被破坏。您所说的“与C共享”是什么意思?对于C++和(Vo>*),代码通常> <代码> 0> <代码> > 0代码> >代码> > IFNDEF,CPLUS PLUS < /COD>。我不知道。作为参考,STL有一个轶事,关于试图改变这一点,并在他们自己的代码中遇到了一系列问题:。奥托,几年后,还是同一个人。
#pragma once
#ifndef _CSTDDEF_
#define _CSTDDEF_
#include <yvals_core.h>
#if _STL_COMPILER_PREPROCESSOR

#include <stddef.h>
#ifndef NULL
    #ifdef __cplusplus
        #define NULL 0
    #else
        #define NULL ((void *)0)
    #endif
#endif
#include <type_traits>
#include <cstddef>

static_assert(!std::is_same<decltype(NULL), std::nullptr_t>::value, "");
static_assert(!std::is_same<decltype(NULL), int>::value, "");
static_assert(std::is_same<decltype(NULL), long>::value, "");