首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

NULL

Defined in header <cstddef>

?

?

Defined in header <cstring>

?

?

Defined in header <cwchar>

?

?

Defined in header <ctime>

?

?

Defined in header <cstdio>

?

?

Defined in header <clocale>

?

?

Defined in header <cstdlib>

?

?

#define NULL /*implementation-defined*/

?

?

NULL是实现定义的空指针常量,它可能是。

an integral constant expression rvalue of integer type that evaluates to zero.

(until C++11)

an integer literal with value zero, or a prvalue of type std::nullptr_t.

(since C++11)

空指针常量可能是隐式转换指向任何指针类型;这种转换将导致该类型的空指针值。如果空指针常量具有整数类型,则可以将其转换为类型的prvalue。std::nullptr_t...

可能的实施

#定义空0//自C++11#定义空nullptr

*。

注记

在C中,宏NULL可能有这种类型void*,但这在C++中是不允许的。

二次

代码语言:javascript
复制
#include <cstddef>
class S;
int main()
{
    int* p = NULL;
    int* p2 = static_cast<std::nullptr_t>(NULL);
    void(*f)(int) = NULL;
    int S::*mp = NULL;
    void(S::*mfp)(int) = NULL;
}

二次

缺陷报告

以下行为更改缺陷报告追溯应用于先前发布的C++标准。

DR

Applied to

Behavior as published

Correct behavior

CWG 903

C++11

constant expressions with zero value such as 1-1 were allowed

only the literal zero is allowed

另见

nullptr

the pointer literal which specifies a null pointer value (C++11)

nullptr_t (C++11)

the type of the null pointer literal nullptr (typedef)

C文档为NULL

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com