I included a check for nullptr
in a line of C code. The compiler (gcc) complained when using -std=c17
as well as -std=gnu17
.
Is there such a thing as nullptr (or equivalent) in modern C standards? (C11, C17)
If not, then why?
No, C still uses NULL
for a null pointer.
C++ needs a dedicated null pointer literal because it has overloading and template type deduction. These features get confused by NULL
, which expands to 0
(or something like that) in C++. However, the risk of such confusion in C is small (maybe _Generic
can get confused by this), and in addition, C can use (void*)0
for a null pointer, which mitigates this risk even more.