ISO C 23 now has nullptr, as well as the nullptr_t type. The proposal that introduced it has some rationale.
ISO C 23 now has nullptr, as well as the nullptr_t type. The proposal that introduced it has some rationale.
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.
Yes it is valid, and it results in a noop. reference
If expression evaluates to a null pointer value, no destructors are called, and the deallocation function is not called.
For destructors, [expr.delete]/6:
If the value of the operand of the delete-expression is not a null pointer value, the delete-expression will invoke the destructor (if any) for the object or the elements of the array being deleted.
This technically doesn't say that if the operand is a null pointer value, the destructor isn't invoked. Probably a minor wording issue?
For deallocation, [expr.delete]/7:
If the value of the operand of the delete-expression is a null pointer value, it is unspecified whether a deallocation function will be called as described above.
Unspecified deallocation, but likely no destruction.
Note also, from [basic.stc.dynamic.deallocation]/3, which clarifies that even if the standard library deallocation function is called in this situation, there is no effect:
The value of the first argument supplied to a deallocation function may be a null pointer value; if so, and if the deallocation function is one supplied in the standard library, the call has no effect.