Rule M4-10-1 (required, implementation, automated)
NULL shall not be used as an integer value. See MISRA C++ 2008 [7] Rule A4-10-1 (required, architecture / design / implementation,automated) Only nullptr literal shall be used as the null-pointer-constant.
Rationale
In C++, the literal NULL is both the null-pointer-constant and an integer type. To meet developer expectations, only nullptr pointer literal shall be used as the null-pointerconstant.
Note that, nullptr pointer literal allows parameters forwarding via a template function.
Example
//% $Id: A4-10-1.cpp 298086 2017-11-24 11:13:27Z michal.szczepankiewicz $
#include <cstddef>
#include <cstdint>
void F1(std::int32_t);
void F2(std::int32_t*);
void F3()
{
F1(0);// Compliant
F1(NULL); // Non-compliant - NULL used as an integer,
// compilable
// f1(nullptr); // Non-compliant - nullptr used as an integer
// compilation error
F2(0);// Non-compliant - 0 used as the null pointer constant
F2(NULL);
// Non-compliant - NULL used as the null pointer constant
F2(nullptr); // Compliant
}
void F4(std::int32_t*);
template <class F, class A>
void F5(F f, A a)
{
F4(a);
}
void F6()
{
// f5(f4, NULL); // Non-compliant - function f4(std::int32_t) not declared
F5(F4, nullptr); // Compliant
}
See also
HIC++ v4.0 [9]: 2.5.3 Use nullptr for the null pointer constant