Next: static_assert
, Previous: bool
, Up: ISO C Keyword Substitutes [Contents][Index]
nullptr
Gnulib module: nullptr
The nullptr
module arranges for nullptr
to act
like standard C and C++.
The nullptr
keyword yields a null pointer. It differs from
the NULL
macro, in that NULL
might be an integer whereas
nullptr
is of a special nullptr_t
type with only one
value, namely nullptr
itself. Using nullptr
can help
some compilers emit more sensible warnings, can avoid the need to cast
a null pointer passed to a function prototyped with an ellipsis, and
removes the need to include <stddef.h>
merely to define
NULL
.
Portability problems fixed by Gnulib:
nullptr
:
For C: GCC 12, Clang 15, and other pre-2023 C compilers.
For C++: pre-2011 C++ compilers.
nullptr
is a sentinel argument:
GCC 13.2 and 14.0.
Portability problems not fixed by Gnulib:
nullptr
is a macro instead of a keyword.
nullptr
does not have the type nullptr_t
.
In C, it has type void *
; in C++ it has an integer type.
nullptr_t
, so
null pointer type checking is more error prone. In C, _Generic
expressions cannot reliably distinguish the type of nullptr
from integer or void *
types. C++ overloading has similar
limitations.