NULL
提供: cppreference.com
ヘッダ <clocale> で定義 | ||
ヘッダ <cstddef> で定義 | ||
ヘッダ <cstdio> で定義 | ||
ヘッダ <cstdlib> で定義 | ||
ヘッダ <cstring> で定義 | ||
ヘッダ <ctime> で定義 | ||
ヘッダ <cwchar> で定義 | ||
#define NULL /*implementation-defined*/ | ||
マクロ NULL
は処理系定義のヌルポインタ定数で、
(C++11未満) | |
ゼロの値を持つ整数リテラル、または std::nullptr_t 型の prvalue です。 | (C++11以上) |
ヌルポインタ定数は任意のポインタ型に暗黙に変換できます。 そのような変換の結果はその型のヌルポインタ値になります。 ヌルポインタ定数が整数型を持つ場合、それは std::nullptr_t 型の prvalue に変換できます。
目次 |
[編集]実装例
#define NULL 0//since C++11#define NULL nullptr |
[編集]ノート
C では、マクロ NULL
は void*
型を持っている場合があります。 これは C++ では許されていません。
[編集]例
Run this code
#include <cstddef>#include <type_traits>#include <iostream>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; if(std::is_same_v<decltype(NULL), std::nullptr_t>){std::cout<<"NULL implemented with type std::nullptr_t\n";}else{std::cout<<"NULL implemented using an integral type\n";}}
出力例:
NULL implemented using an integral type
[編集]欠陥報告
以下の動作変更欠陥報告は以前に発行された C++ 標準に遡って適用されました。
DR | 適用先 | 発行時の動作 | 正しい動作 |
---|---|---|---|
CWG 903 | C++11 | constant expressions with zero value such as 1-1 were allowed | only the literal zero is allowed |
[編集]関連項目
nullptr(C++11) | ヌルポインタ値を指定するポインタリテラル |
(C++11) | ヌルポインタリテラル nullptr の型 (typedef) |
NULL の C言語リファレンス |